Avoid recursion issues for the typing module

This commit is contained in:
Dave Halter
2018-07-29 00:10:54 +02:00
parent 35361f4edc
commit cdb96bff47
2 changed files with 12 additions and 2 deletions

View File

@@ -219,6 +219,14 @@ _typing_module = None
_typing_module_code_lines = None _typing_module_code_lines = None
class TypingModuleContext(ModuleContext):
"""
TODO this is currently used for recursion checks. We should just completely
refactor the typing module integration.
"""
pass
def _get_typing_replacement_module(grammar): def _get_typing_replacement_module(grammar):
""" """
The idea is to return our jedi replacement for the PEP-0484 typing module The idea is to return our jedi replacement for the PEP-0484 typing module
@@ -263,7 +271,7 @@ def py__getitem__(context, typ, node):
return context.eval_node(nodes[0]) return context.eval_node(nodes[0])
module_node, code_lines = _get_typing_replacement_module(context.evaluator.latest_grammar) module_node, code_lines = _get_typing_replacement_module(context.evaluator.latest_grammar)
typing = ModuleContext( typing = TypingModuleContext(
context.evaluator, context.evaluator,
module_node=module_node, module_node=module_node,
path=None, path=None,

View File

@@ -116,7 +116,9 @@ class ExecutionRecursionDetector(object):
self._parent_execution_funcs.append(funcdef) self._parent_execution_funcs.append(funcdef)
module = execution.get_root_context() module = execution.get_root_context()
if module == self._evaluator.builtins_module:
from jedi.evaluate.pep0484 import TypingModuleContext
if module == self._evaluator.builtins_module or isinstance(module, TypingModuleContext):
# We have control over builtins so we know they are not recursing # We have control over builtins so we know they are not recursing
# like crazy. Therefore we just let them execute always, because # like crazy. Therefore we just let them execute always, because
# they usually just help a lot with getting good results. # they usually just help a lot with getting good results.