From 6abd96a398b5905931321f859517f77b6a97bc74 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Sat, 8 Sep 2018 17:48:00 +0200 Subject: [PATCH] Try to introduce a few new classes to better deal with compiled objects --- jedi/plugins/typeshed.py | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/jedi/plugins/typeshed.py b/jedi/plugins/typeshed.py index 8a8dd2a0..b43d28e5 100644 --- a/jedi/plugins/typeshed.py +++ b/jedi/plugins/typeshed.py @@ -190,7 +190,12 @@ class NameWithStubMixin(object): for actual_context in actual_contexts: for stub_context in stub_contexts: if isinstance(actual_context, CompiledObject): - yield StubContextWithCompiled(stub_context, actual_context) + if isinstance(stub_context, ClassContext): + yield CompiledStubClassContext(stub_context, actual_context) + elif isinstance(stub_context, FunctionContext): + yield CompiledStubFunctionContext(stub_context, actual_context) + else: + yield stub_context elif isinstance(stub_context, FunctionContext) \ and isinstance(actual_context, FunctionContext): yield StubFunctionContext( @@ -393,9 +398,9 @@ class StubOnlyModuleContext(ModuleContext): yield f -class StubContextWithCompiled(ContextWrapper): +class _StubContextWithCompiled(ContextWrapper): def __init__(self, stub_context, compiled_context): - super(StubContextWithCompiled, self).__init__(stub_context) + super(_StubContextWithCompiled, self).__init__(stub_context) self.compiled_context = compiled_context def py__doc__(self, include_call_signature=False): @@ -407,6 +412,32 @@ class StubContextWithCompiled(ContextWrapper): return doc +class CompiledStubClassContext(_StubContextWithCompiled): + def get_filters(self, search_global=False, until_position=None, + origin_scope=None, **kwargs): + filters = self._wrapped_context.get_filters( + search_global, until_position, origin_scope, **kwargs + ) + next(filters) # Ignore the first filter and replace it with our own + + # Here we remap the names from stubs to the actual module. This is + # important if type inferences is needed in that module. + yield StubParserTreeFilter( + [next(self.compiled_context.get_filters(search_global=search_global, **kwargs))], + self.evaluator, + context=self, + until_position=until_position, + origin_scope=origin_scope, + search_global=search_global, + ) + for f in filters: + yield f + + +class CompiledStubFunctionContext(_StubContextWithCompiled): + pass + + class TypingModuleWrapper(StubOnlyModuleContext): def get_filters(self, *args, **kwargs): filters = super(TypingModuleWrapper, self).get_filters(*args, **kwargs)