Skip to content

Commit

Permalink
Fix bug in Python 2.7 string dep inference. (#11900)
Browse files Browse the repository at this point in the history
[ci skip-rust]

[ci skip-build-wheels]
  • Loading branch information
benjyw committed Apr 13, 2021
1 parent ab18c94 commit e75cb0a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Expand Up @@ -82,8 +82,11 @@ def visit_Call(self, node):
# logic.
if sys.version_info[0:2] == (2,7):
def visit_Str(self, node):
val = node.s.decode("utf-8") if isinstance(node.s, bytes) else node.s
self.maybe_add_string_import(val)
try:
val = node.s.decode("utf8") if isinstance(node.s, bytes) else node.s
self.maybe_add_string_import(val)
except UnicodeError:
pass
setattr(AstVisitor, 'visit_Str', visit_Str)
Expand Down
Expand Up @@ -212,6 +212,8 @@ def test_works_with_python2(rule_runner: RuleRunner) -> None:
importlib.import_module(b"dep.from.bytes")
importlib.import_module(u"dep.from.str")
importlib.import_module(u"dep.from.str_狗")
b"\\xa0 a non-utf8 string, make sure we ignore it"
"""
)
assert_imports_parsed(
Expand Down

0 comments on commit e75cb0a

Please sign in to comment.