Fix some tests because of stub_context changes

This commit is contained in:
Dave Halter
2019-03-16 01:06:13 +01:00
parent fce37fa0e3
commit e2fea0a5de
4 changed files with 16 additions and 19 deletions

View File

@@ -336,7 +336,10 @@ class FunctionExecutionContext(TreeContext):
# Only the first generic is relevant. # Only the first generic is relevant.
generics = (return_contexts.py__class__(), NO_CONTEXTS, NO_CONTEXTS) generics = (return_contexts.py__class__(), NO_CONTEXTS, NO_CONTEXTS)
return ContextSet( return ContextSet(
AnnotatedSubClass(getattr(c, 'stub_context', c), generics) for c in async_classes AnnotatedSubClass(
c if c.stub_context is None else c.stub_context,
generics
) for c in async_classes
).execute_annotation() ).execute_annotation()
else: else:
if is_generator: if is_generator:

View File

@@ -395,11 +395,8 @@ class BoundMethod(FunctionMixin, ContextWrapper):
# This might not be the most beautiful way, but prefer stub_contexts # This might not be the most beautiful way, but prefer stub_contexts
# and execute those if possible. # and execute those if possible.
try: stub_context = self._wrapped_context.stub_context
stub_context = self._wrapped_context.stub_context if stub_context is not None:
except AttributeError:
pass
else:
return stub_context.py__call__(arguments) return stub_context.py__call__(arguments)
function_execution = self.get_function_execution(arguments) function_execution = self.get_function_execution(arguments)

View File

@@ -513,19 +513,16 @@ class AbstractAnnotatedClass(ClassMixin, ContextWrapper):
filter_ = super(AbstractAnnotatedClass, self)._create_class_filter( filter_ = super(AbstractAnnotatedClass, self)._create_class_filter(
cls, origin_scope, is_instance cls, origin_scope, is_instance
) )
try: if cls.stub_context is None:
stub_context = cls.stub_context
except AttributeError:
return filter_ return filter_
else: return cls.stub_context.get_stub_only_filter(
return stub_context.get_stub_only_filter( # Take the first filter, which is here to filter module contents
# Take the first filter, which is here to filter module contents # and wrap it.
# and wrap it. self.parent_context,
self.parent_context, [filter_],
[filter_], search_global=False,
search_global=False, origin_scope=origin_scope,
origin_scope=origin_scope, )
)
def get_filters(self, search_global=False, *args, **kwargs): def get_filters(self, search_global=False, *args, **kwargs):
filters = super(AbstractAnnotatedClass, self).get_filters( filters = super(AbstractAnnotatedClass, self).get_filters(

View File

@@ -190,7 +190,7 @@ def test_goto_stubs(Script):
'import os; os.walk' 'import os; os.walk'
'from collections import Counter; Counter' 'from collections import Counter; Counter'
]) ])
def test_goto_stubs_on_itself(Script): def test_goto_stubs_on_itself(Script, code):
""" """
If goto_stubs is used on an identifier in e.g. the stdlib, we should goto If goto_stubs is used on an identifier in e.g. the stdlib, we should goto
the stub of it. the stub of it.