A small speed optimization that helps a lot with sys.version_info >= (3, 0) patterns in typeshed

This commit is contained in:
Dave Halter
2019-08-10 15:30:51 +02:00
parent 4a5c992b1a
commit 0a84678a60

View File

@@ -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