forked from VimPlug/jedi
Remove UserContextParser again from docstring stuff, not really needed there. use a simpler solution
This commit is contained in:
@@ -17,7 +17,7 @@ annotations.
|
||||
import re
|
||||
|
||||
from jedi.evaluate.cache import memoize_default
|
||||
from jedi.parser.user_context import UserContextParser
|
||||
from jedi.parser import Parser
|
||||
|
||||
DOCSTRING_PARAM_PATTERNS = [
|
||||
r'\s*:type\s+%s:\s*([^\n]+)', # Sphinx
|
||||
@@ -37,7 +37,7 @@ def follow_param(evaluator, param):
|
||||
func = param.parent_function
|
||||
# print func, param, param.parent_function
|
||||
param_str = _search_param_in_docstr(func.docstr, str(param.get_name()))
|
||||
user_position = (1, 0)
|
||||
position = (1, 0)
|
||||
|
||||
if param_str is not None:
|
||||
|
||||
@@ -47,12 +47,13 @@ def follow_param(evaluator, param):
|
||||
param_str = 'import %s\n%s' % (
|
||||
param_str.rsplit('.', 1)[0],
|
||||
param_str)
|
||||
user_position = (2, 0)
|
||||
position = (2, 0)
|
||||
|
||||
p = UserContextParser(param_str, None, user_position, no_docstr=True)
|
||||
if p.user_stmt() is None:
|
||||
p = Parser(param_str, no_docstr=True)
|
||||
stmt = p.module.get_statement_for_position(position)
|
||||
if stmt is None:
|
||||
return []
|
||||
return evaluator.eval_statement(p.user_stmt())
|
||||
return evaluator.eval_statement(stmt)
|
||||
return []
|
||||
|
||||
|
||||
@@ -115,8 +116,9 @@ def find_return_types(evaluator, func):
|
||||
if not type_str:
|
||||
return []
|
||||
|
||||
p = UserContextParser(type_str, None, (1, 0), no_docstr=True)
|
||||
if p.user_stmt() is None:
|
||||
p = Parser(type_str, None, no_docstr=True)
|
||||
stmt = p.module.get_statement_for_position((1, 0))
|
||||
if stmt is None:
|
||||
return []
|
||||
p.user_stmt().parent = func
|
||||
return list(evaluator.eval_statement(p.user_stmt()))
|
||||
stmt.parent = func
|
||||
return list(evaluator.eval_statement(stmt))
|
||||
|
||||
@@ -3,7 +3,7 @@ import os
|
||||
import sys
|
||||
|
||||
from jedi import cache
|
||||
from jedi.parser import tokenize, Parser
|
||||
from jedi.parser import tokenize
|
||||
from jedi.parser.fast import FastParser
|
||||
from jedi.parser import representation
|
||||
from jedi import debug
|
||||
@@ -181,22 +181,18 @@ class UserContext(object):
|
||||
|
||||
|
||||
class UserContextParser(object):
|
||||
def __init__(self, source, path, position, user_context=None, no_docstr=False):
|
||||
def __init__(self, source, path, position, user_context):
|
||||
self._source = source
|
||||
self._path = path and os.path.abspath(path)
|
||||
self._position = position
|
||||
self._user_context = user_context
|
||||
self._no_docstr = no_docstr
|
||||
|
||||
@cache.underscore_memoization
|
||||
def _parser(self):
|
||||
cache.invalidate_star_import_cache(self._path)
|
||||
if self._no_docstr:
|
||||
parser = Parser(self._source, self._path, no_docstr=self._no_docstr)
|
||||
else:
|
||||
parser = FastParser(self._source, self._path)
|
||||
# Don't pickle that module, because the main module is changing quickly
|
||||
cache.save_parser(self._path, None, parser, pickling=False)
|
||||
parser = FastParser(self._source, self._path)
|
||||
# Don't pickle that module, because the main module is changing quickly
|
||||
cache.save_parser(self._path, None, parser, pickling=False)
|
||||
return parser
|
||||
|
||||
@cache.underscore_memoization
|
||||
|
||||
Reference in New Issue
Block a user