mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-09 07:14:48 +08:00
Fix stub_to_actual_context_set for bound methods
This commit is contained in:
@@ -14,6 +14,16 @@ def stub_to_actual_context_set(stub_context, ignore_compiled=False):
|
|||||||
stub_context = stub_context.py__class__()
|
stub_context = stub_context.py__class__()
|
||||||
|
|
||||||
qualified_names = stub_context.get_qualified_names()
|
qualified_names = stub_context.get_qualified_names()
|
||||||
|
if qualified_names is None:
|
||||||
|
return NO_CONTEXTS
|
||||||
|
|
||||||
|
was_bound_method = stub_context.is_bound_method()
|
||||||
|
if was_bound_method:
|
||||||
|
# Infer the object first. We can infer the method later.
|
||||||
|
method_name = qualified_names[-1]
|
||||||
|
qualified_names = qualified_names[:-1]
|
||||||
|
was_instance = True
|
||||||
|
|
||||||
contexts = _infer_from_stub(stub_module, qualified_names, ignore_compiled)
|
contexts = _infer_from_stub(stub_module, qualified_names, ignore_compiled)
|
||||||
if was_instance:
|
if was_instance:
|
||||||
contexts = ContextSet.from_sets(
|
contexts = ContextSet.from_sets(
|
||||||
@@ -21,13 +31,14 @@ def stub_to_actual_context_set(stub_context, ignore_compiled=False):
|
|||||||
for c in contexts
|
for c in contexts
|
||||||
if c.is_class()
|
if c.is_class()
|
||||||
)
|
)
|
||||||
|
if was_bound_method:
|
||||||
|
# Now that the instance has been properly created, we can simply get
|
||||||
|
# the method.
|
||||||
|
contexts = contexts.py__getattribute__(method_name)
|
||||||
return contexts
|
return contexts
|
||||||
|
|
||||||
|
|
||||||
def _infer_from_stub(stub_module, qualified_names, ignore_compiled):
|
def _infer_from_stub(stub_module, qualified_names, ignore_compiled):
|
||||||
if qualified_names is None:
|
|
||||||
return NO_CONTEXTS
|
|
||||||
|
|
||||||
assert isinstance(stub_module, StubModuleContext), stub_module
|
assert isinstance(stub_module, StubModuleContext), stub_module
|
||||||
non_stubs = stub_module.non_stub_context_set
|
non_stubs = stub_module.non_stub_context_set
|
||||||
if ignore_compiled:
|
if ignore_compiled:
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ from jedi.evaluate.gradual.conversion import stub_to_actual_context_set
|
|||||||
('bytes.partition', 'partition(self, sep, /)', ['self', 'sep'], ge, (3, 5)),
|
('bytes.partition', 'partition(self, sep, /)', ['self', 'sep'], ge, (3, 5)),
|
||||||
|
|
||||||
('bytes().partition', 'partition(sep) -> (head, sep, tail)', ['sep'], lt, (3, 5)),
|
('bytes().partition', 'partition(sep) -> (head, sep, tail)', ['sep'], lt, (3, 5)),
|
||||||
('bytes().partition', 'partition(sep, /)', ['sep'], ge, (3, 5)),
|
('bytes().partition', 'partition(self, sep, /)', ['sep'], ge, (3, 5)),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
def test_compiled_signature(Script, environment, code, sig, names, op, version):
|
def test_compiled_signature(Script, environment, code, sig, names, op, version):
|
||||||
|
|||||||
Reference in New Issue
Block a user