From 848cf47b9abad5c9c66c15d00bb66483443eae64 Mon Sep 17 00:00:00 2001 From: gpotter2 Date: Thu, 21 Oct 2021 14:07:09 +0200 Subject: [PATCH] Fix advanced class completion --- bpython/repl.py | 2 -- bpython/test/test_repl.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/bpython/repl.py b/bpython/repl.py index e261e61a..5d664e65 100644 --- a/bpython/repl.py +++ b/bpython/repl.py @@ -601,8 +601,6 @@ def get_args(self): if inspect.isclass(f): class_f = None - if hasattr(f, "__init__") and f.__init__ is not object.__init__: - class_f = f.__init__ if ( (not class_f or not inspection.getfuncprops(func, class_f)) and hasattr(f, "__new__") diff --git a/bpython/test/test_repl.py b/bpython/test/test_repl.py index 65a2fb81..e29c5a4e 100644 --- a/bpython/test/test_repl.py +++ b/bpython/test/test_repl.py @@ -482,6 +482,34 @@ def test_paremeter_name_completion(self): self.repl.matches_iter.matches, ["abc=", "abd=", "abs("] ) + def test_parameter_advanced_on_class(self): + self.repl = FakeRepl( + {"autocomplete_mode": autocomplete.AutocompleteModes.SIMPLE} + ) + self.set_input_line("TestCls(app") + + code = """ + import inspect + + class TestCls: + # A class with boring __init__ typing + def __init__(self, *args, **kwargs): + pass + # But that uses super exotic typings recognized by inspect.signature + __signature__ = inspect.Signature([ + inspect.Parameter("apple", inspect.Parameter.POSITIONAL_ONLY), + inspect.Parameter("apple2", inspect.Parameter.KEYWORD_ONLY), + inspect.Parameter("pinetree", inspect.Parameter.KEYWORD_ONLY), + ]) + """ + for line in code.split("\n"): + print(line[8:]) + self.repl.push(line[8:]) + + self.assertTrue(self.repl.complete()) + self.assertTrue(hasattr(self.repl.matches_iter, "matches")) + self.assertEqual(self.repl.matches_iter.matches, ["apple2=", "apple="]) + class TestCliRepl(unittest.TestCase): def setUp(self):