diff --git a/lib/python/pyflyby/_parse.py b/lib/python/pyflyby/_parse.py index 6ee6730f..263c7717 100644 --- a/lib/python/pyflyby/_parse.py +++ b/lib/python/pyflyby/_parse.py @@ -19,7 +19,6 @@ from pyflyby._log import logger from pyflyby._util import cached_attribute, cmp -from ast import Bytes from ast import TypeIgnore, AsyncFunctionDef @@ -42,8 +41,17 @@ def _is_ast_str_or_byte(node) -> bool: utility function that test if node is an ast.Str|ast.Bytes in Python < 3.12, and if it is a ast.Constant, with node.value being a str in newer version. """ - return isinstance(node, Bytes) or _is_ast_str(node) + return _is_ast_str(node) or _is_ast_bytes(node) +def _is_ast_bytes(node) -> bool: + """ + utility function that test if node is an ast.Str in Python < 3.12, + and if it is a ast.Constant, with node.value being a str in newer version. + """ + if sys.version_info < (3,12): + return isinstance(node, ast.Bytes) + else: + return (isinstance(node, ast.Constant) and isinstance(node.value , bytes)) def _is_ast_str(node) -> bool: