cache the parsed jedi_typing module

This commit is contained in:
Claude
2016-01-23 23:06:28 +01:00
parent e267f63657
commit 244c9976e5
+12 -7
View File
@@ -77,18 +77,23 @@ def find_return_types(evaluator, func):
return _evaluate_for_annotation(evaluator, annotation) return _evaluate_for_annotation(evaluator, annotation)
# TODO: Memoize _typing_module = None
def _get_typing_replacement_module(): def _get_typing_replacement_module():
""" """
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
as discussed at https://github.com/davidhalter/jedi/issues/663 as discussed at https://github.com/davidhalter/jedi/issues/663
""" """
global _typing_module
typing_path = os.path.abspath(os.path.join(__file__, "../jedi_typing.py")) if _typing_module is None:
with open(typing_path) as f: typing_path = \
code = _compatibility.unicode(f.read()) os.path.abspath(os.path.join(__file__, "../jedi_typing.py"))
p = ParserWithRecovery(load_grammar(), code) with open(typing_path) as f:
return p.module code = _compatibility.unicode(f.read())
p = ParserWithRecovery(load_grammar(), code)
_typing_module = p.module
return _typing_module
def get_types_for_typing_module(evaluator, typ, node): def get_types_for_typing_module(evaluator, typ, node):