1
0
forked from VimPlug/jedi

Add a latest grammar to the evaluator and use it to avoid importing from parso import parse.

This commit is contained in:
Dave Halter
2017-05-24 00:37:36 -04:00
parent b90589b62e
commit cd8932fbfc
10 changed files with 31 additions and 26 deletions

View File

@@ -20,10 +20,12 @@ x support for type hint comments for functions, `# type: (int, str) -> int`.
"""
import itertools
import os
import re
from parso import ParserSyntaxError
from parso.python import parse, tree
from parso.python import tree
from jedi.common import unite
from jedi.evaluate.cache import memoize_default
from jedi.evaluate import compiled
@@ -31,7 +33,6 @@ from jedi.evaluate.context import LazyTreeContext
from jedi import debug
from jedi import _compatibility
from jedi import parser_utils
import re
def _evaluate_for_annotation(context, annotation, index=None):
@@ -63,7 +64,7 @@ def _fix_forward_reference(context, node):
if isinstance(evaled_node, compiled.CompiledObject) and \
isinstance(evaled_node.obj, str):
try:
new_node = parse(
new_node = context.evaluator.grammar.parse(
_compatibility.unicode(evaled_node.obj),
start_symbol='eval_input',
error_recovery=False
@@ -110,7 +111,7 @@ def infer_return_types(function_context):
_typing_module = None
def _get_typing_replacement_module():
def _get_typing_replacement_module(grammar):
"""
The idea is to return our jedi replacement for the PEP-0484 typing module
as discussed at https://github.com/davidhalter/jedi/issues/663
@@ -121,7 +122,7 @@ def _get_typing_replacement_module():
os.path.abspath(os.path.join(__file__, "../jedi_typing.py"))
with open(typing_path) as f:
code = _compatibility.unicode(f.read())
_typing_module = parse(code)
_typing_module = grammar.parse(code)
return _typing_module
@@ -155,7 +156,7 @@ def py__getitem__(context, typ, node):
from jedi.evaluate.representation import ModuleContext
typing = ModuleContext(
context.evaluator,
module_node=_get_typing_replacement_module(),
module_node=_get_typing_replacement_module(context.evaluator.latest_grammar),
path=None
)
factories = typing.py__getattribute__("factory")