mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 23:04:48 +08:00
Rewrite the typeshed algorithm of matching actual and stub classes
This commit is contained in:
@@ -192,54 +192,35 @@ class StubName(NameWrapper):
|
|||||||
@memoize_method
|
@memoize_method
|
||||||
@iterator_to_context_set
|
@iterator_to_context_set
|
||||||
def infer(self):
|
def infer(self):
|
||||||
actual_contexts = self._wrapped_name.infer()
|
|
||||||
stub_contexts = self._stub_name.infer()
|
stub_contexts = self._stub_name.infer()
|
||||||
|
if not stub_contexts:
|
||||||
if not actual_contexts:
|
for c in self._wrapped_name.infer():
|
||||||
for c in stub_contexts:
|
|
||||||
yield c
|
yield c
|
||||||
|
return
|
||||||
|
|
||||||
# This basically merges stub contexts with actual contexts.
|
typ = self._wrapped_name.tree_name.parent.type
|
||||||
for actual_context in actual_contexts:
|
if typ in ('classdef', 'funcdef'):
|
||||||
|
actual_context, = self._wrapped_name.infer()
|
||||||
for stub_context in stub_contexts:
|
for stub_context in stub_contexts:
|
||||||
if isinstance(stub_context, FunctionContext) \
|
if isinstance(stub_context, MethodContext):
|
||||||
and isinstance(actual_context, FunctionContext):
|
assert isinstance(actual_context, MethodContext)
|
||||||
if isinstance(actual_context, MethodContext):
|
|
||||||
assert isinstance(stub_context, MethodContext)
|
|
||||||
cls = StubMethodContext
|
cls = StubMethodContext
|
||||||
else:
|
elif isinstance(stub_context, FunctionContext):
|
||||||
cls = StubFunctionContext
|
cls = StubFunctionContext
|
||||||
|
elif isinstance(stub_context, StubOnlyClass):
|
||||||
|
cls = StubClassContext
|
||||||
|
else:
|
||||||
|
yield stub_context
|
||||||
|
continue
|
||||||
yield cls.create_cached(
|
yield cls.create_cached(
|
||||||
actual_context.evaluator,
|
actual_context.evaluator,
|
||||||
self.parent_context,
|
self.parent_context,
|
||||||
actual_context,
|
actual_context,
|
||||||
stub_context,
|
stub_context,
|
||||||
)
|
)
|
||||||
elif isinstance(stub_context, StubOnlyClass) \
|
|
||||||
and isinstance(actual_context, ClassContext):
|
|
||||||
yield StubClassContext.create_cached(
|
|
||||||
actual_context.evaluator,
|
|
||||||
self.parent_context,
|
|
||||||
actual_context,
|
|
||||||
stub_context,
|
|
||||||
)
|
|
||||||
elif isinstance(stub_context, VersionInfo):
|
|
||||||
# TODO needed?
|
|
||||||
yield stub_context
|
|
||||||
elif isinstance(actual_context, CompiledObject):
|
|
||||||
if stub_context.is_class():
|
|
||||||
yield CompiledStubClass.create_cached(
|
|
||||||
stub_context.evaluator, stub_context, actual_context)
|
|
||||||
elif stub_context.is_function():
|
|
||||||
yield CompiledStubFunction.create_cached(
|
|
||||||
stub_context.evaluator, stub_context, actual_context)
|
|
||||||
else:
|
else:
|
||||||
yield stub_context
|
for c in stub_contexts:
|
||||||
else:
|
yield c
|
||||||
yield stub_context
|
|
||||||
|
|
||||||
if not stub_contexts:
|
|
||||||
yield actual_context
|
|
||||||
|
|
||||||
|
|
||||||
class CompiledStubName(NameWrapper):
|
class CompiledStubName(NameWrapper):
|
||||||
@@ -262,7 +243,11 @@ class CompiledStubName(NameWrapper):
|
|||||||
|
|
||||||
for actual_context in compiled_contexts:
|
for actual_context in compiled_contexts:
|
||||||
for stub_context in stub_contexts:
|
for stub_context in stub_contexts:
|
||||||
if stub_context.is_class():
|
if isinstance(stub_context, _CompiledStubContext):
|
||||||
|
# It's already a stub context, e.g. bytes in Python 2
|
||||||
|
# behaves this way.
|
||||||
|
yield stub_context
|
||||||
|
elif stub_context.is_class():
|
||||||
yield CompiledStubClass.create_cached(
|
yield CompiledStubClass.create_cached(
|
||||||
stub_context.evaluator, stub_context, actual_context)
|
stub_context.evaluator, stub_context, actual_context)
|
||||||
elif stub_context.is_function():
|
elif stub_context.is_function():
|
||||||
|
|||||||
Reference in New Issue
Block a user