Skip to content

Commit

Permalink
Ensure pygram is initialized before use
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac-HD committed Feb 7, 2024
1 parent a201003 commit 8ab7a22
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/blib2to3/pytree.py
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 8ab7a22

Please sign in to comment.