Skip to content

Commit 126b059

Browse files
gpotter2sebastinas
authored andcommitted
Fix advanced class completion
1 parent f9b21ca commit 126b059

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

bpython/repl.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -601,8 +601,6 @@ def get_args(self):
601601
if inspect.isclass(f):
602602
class_f = None
603603

604-
if hasattr(f, "__init__") and f.__init__ is not object.__init__:
605-
class_f = f.__init__
606604
if (
607605
(not class_f or not inspection.getfuncprops(func, class_f))
608606
and hasattr(f, "__new__")

bpython/test/test_repl.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,34 @@ def test_paremeter_name_completion(self):
482482
self.repl.matches_iter.matches, ["abc=", "abd=", "abs("]
483483
)
484484

485+
def test_parameter_advanced_on_class(self):
486+
self.repl = FakeRepl(
487+
{"autocomplete_mode": autocomplete.AutocompleteModes.SIMPLE}
488+
)
489+
self.set_input_line("TestCls(app")
490+
491+
code = """
492+
import inspect
493+
494+
class TestCls:
495+
# A class with boring __init__ typing
496+
def __init__(self, *args, **kwargs):
497+
pass
498+
# But that uses super exotic typings recognized by inspect.signature
499+
__signature__ = inspect.Signature([
500+
inspect.Parameter("apple", inspect.Parameter.POSITIONAL_ONLY),
501+
inspect.Parameter("apple2", inspect.Parameter.KEYWORD_ONLY),
502+
inspect.Parameter("pinetree", inspect.Parameter.KEYWORD_ONLY),
503+
])
504+
"""
505+
for line in code.split("\n"):
506+
print(line[8:])
507+
self.repl.push(line[8:])
508+
509+
self.assertTrue(self.repl.complete())
510+
self.assertTrue(hasattr(self.repl.matches_iter, "matches"))
511+
self.assertEqual(self.repl.matches_iter.matches, ["apple2=", "apple="])
512+
485513

486514
class TestCliRepl(unittest.TestCase):
487515
def setUp(self):

0 commit comments

Comments
 (0)