From 0a84678a6073b7dd1ce26141d0305e590bdaf7d0 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Sat, 10 Aug 2019 15:30:51 +0200 Subject: [PATCH] A small speed optimization that helps a lot with sys.version_info >= (3, 0) patterns in typeshed --- jedi/evaluate/context/iterable.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/jedi/evaluate/context/iterable.py b/jedi/evaluate/context/iterable.py index 91b6f54d..56927f8f 100644 --- a/jedi/evaluate/context/iterable.py +++ b/jedi/evaluate/context/iterable.py @@ -35,7 +35,7 @@ from jedi.evaluate.utils import safe_property, to_list from jedi.evaluate.cache import evaluator_method_cache from jedi.evaluate.filters import ParserTreeFilter, LazyAttributeOverwrite, \ publish_method -from jedi.evaluate.base_context import ContextSet, NO_CONTEXTS, \ +from jedi.evaluate.base_context import ContextSet, Context, NO_CONTEXTS, \ TreeContext, ContextualizedNode, iterate_contexts, HelperContextMixin from jedi.parser_utils import get_sync_comp_fors @@ -44,6 +44,14 @@ class IterableMixin(object): def py__stop_iteration_returns(self): return ContextSet([compiled.builtin_from_name(self.evaluator, u'None')]) + # At the moment, safe values are simple values like "foo", 1 and not + # lists/dicts. Therefore as a small speed optimization we can just do the + # default instead of resolving the lazy wrapped contexts, that are just + # doing this in the end as well. + # This mostly speeds up patterns like `sys.version_info >= (3, 0)` in + # typeshed. + get_safe_value = Context.get_safe_value + class GeneratorBase(LazyAttributeOverwrite, IterableMixin): array_type = None