Skip to content

Commit

Permalink
dont ast.Bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
Carreau committed Feb 26, 2024
1 parent 8b2c454 commit 2a5cfca
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/python/pyflyby/_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand Down

0 comments on commit 2a5cfca

Please sign in to comment.