Skip to content

Commit

Permalink
Workaround for a bug in astunparse, fixing #22
Browse files Browse the repository at this point in the history
  • Loading branch information
ESultanik committed Sep 7, 2022
1 parent 4989663 commit 1951a7c
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions fickling/pickle.py
Expand Up @@ -46,7 +46,6 @@ def make_constant(*args, **kwargs) -> ast.Constant:
make_constant = ast.Constant

BUILTIN_MODULE_NAMES: FrozenSet[str] = frozenset(sys.builtin_module_names)
del sys

OPCODES_BY_NAME: Dict[str, Type["Opcode"]] = {}
OPCODE_INFO_BY_NAME: Dict[str, OpcodeInfo] = {opcode.name: opcode for opcode in opcodes}
Expand Down Expand Up @@ -597,8 +596,13 @@ def run(self, interpreter: Interpreter):
# no need to emit an import for builtins!
pass
else:
if sys.version_info < (3, 9):
# workaround for a bug in astunparse
alias = ast.alias(attr, asname=None)
else:
alias = ast.alias(attr)
interpreter.module_body.append(
ast.ImportFrom(module=module, names=[ast.alias(attr)], level=0)
ast.ImportFrom(module=module, names=[alias], level=0)
)
interpreter.stack.append(ast.Name(attr, ast.Load()))

Expand All @@ -620,8 +624,13 @@ def run(self, interpreter: Interpreter):
# no need to emit an import for builtins!
pass
else:
if sys.version_info < (3, 9):
# workaround for a bug in astunparse
alias = ast.alias(attr, asname=None)
else:
alias = ast.alias(attr)
interpreter.module_body.append(
ast.ImportFrom(module=module, names=[ast.alias(attr)], level=0)
ast.ImportFrom(module=module, names=[alias], level=0)
)
interpreter.stack.append(ast.Name(attr, ast.Load()))

Expand Down

0 comments on commit 1951a7c

Please sign in to comment.