Skip to content

Commit

Permalink
Add failing tests for deshaw#318
Browse files Browse the repository at this point in the history
This adds a failing test.
  • Loading branch information
Carreau committed Mar 18, 2024
1 parent 96dcc54 commit b9897f8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/python/pyflyby/_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ def __new__(cls, arg, filename=None, startpos=None, flags=None,
return cls.from_text(
arg, filename=filename, startpos=startpos,
flags=flags, auto_flags=auto_flags)
raise TypeError("%s: unexpected %s"
raise TypeError("%r: unexpected %r"
% (cls.__name__, type(arg).__name__,))

@classmethod
Expand Down
23 changes: 23 additions & 0 deletions tests/test_imports2s.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,29 @@ def selfref():
assert output == expected


def test_fix_missing_imports_other_class():
"""
This insert import for type annotations, only if a class is present before.
See https://github.com/deshaw/pyflyby/issues/318
"""
data = dedent("""
from __future__ import annotations
class _TestCls():
class WrappedFunction():
pass
class Popen():
def test(self) -> Popen:
return None""")
b = PythonBlock(data)
db = ImportDB("from subprocess import Popen")
output = fix_unused_and_missing_imports(b, db=db)
expected = PythonBlock(data)
assert output == expected


def test_fix_unused_and_missing_continutation_1():
input = PythonBlock(dedent(r'''
a#\
Expand Down

0 comments on commit b9897f8

Please sign in to comment.