Skip to content

Commit 8716194

Browse files
committed
add-test-for-unsafe-attr-completion
1 parent d4cd689 commit 8716194

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

tests/test_completer.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,6 +1572,39 @@ def __getattr__(self, attr):
15721572
self.assertNotIn(".append", matches)
15731573
self.assertNotIn(".keys", matches)
15741574

1575+
def test_completion_fallback_to_annotation_for_attribute(self):
1576+
code = textwrap.dedent(
1577+
"""
1578+
class StringMethods:
1579+
def a():
1580+
pass
1581+
1582+
class Test:
1583+
str: StringMethods
1584+
def __init__(self):
1585+
self.str = StringMethods()
1586+
def __getattr__(self, name):
1587+
raise AttributeError(f"{name} not found")
1588+
"""
1589+
)
1590+
1591+
repro = types.ModuleType("repro")
1592+
sys.modules["repro"] = repro
1593+
exec(code, repro.__dict__)
1594+
1595+
ip = get_ipython()
1596+
ip.user_ns["repro"] = repro
1597+
exec("r = repro.Test()", ip.user_ns)
1598+
1599+
complete = ip.Completer.complete
1600+
try:
1601+
with evaluation_policy("limited"), jedi_status(False):
1602+
_, matches = complete(line_buffer="r.str.")
1603+
self.assertIn(".a", matches)
1604+
finally:
1605+
sys.modules.pop("repro", None)
1606+
ip.user_ns.pop("r", None)
1607+
15751608
def test_policy_warnings(self):
15761609
with self.assertWarns(
15771610
UserWarning,

0 commit comments

Comments
 (0)