Skip to content

Fix advanced class completion #932

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions bpython/repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__")
Expand Down
28 changes: 28 additions & 0 deletions bpython/test/test_repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down