Skip to content

Commit

Permalink
Ensure blib2to3.pygram is initialized before use (#4224)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac-HD authored Mar 3, 2024
1 parent e4bfedb commit f03ee11
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/blib2to3/pytree.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,15 @@
def type_repr(type_num: int) -> Union[str, int]:
global _type_reprs
if not _type_reprs:
from .pygram import python_symbols
from . import pygram

if not hasattr(pygram, "python_symbols"):
pygram.initialize(cache_dir=None)

# printing tokens is possible but not as useful
# from .pgen2 import token // token.__dict__.items():
for name in dir(python_symbols):
val = getattr(python_symbols, name)
for name in dir(pygram.python_symbols):
val = getattr(pygram.python_symbols, name)
if type(val) == int:
_type_reprs[val] = name
return _type_reprs.setdefault(type_num, type_num)
Expand Down

0 comments on commit f03ee11

Please sign in to comment.