1
0
forked from VimPlug/jedi

Remove UserContextParser again from docstring stuff, not really needed there. use a simpler solution

This commit is contained in:
Dave Halter
2014-01-17 03:06:07 +01:00
parent aa59aee3dc
commit cd40e213ce
2 changed files with 17 additions and 19 deletions

View File

@@ -17,7 +17,7 @@ annotations.
import re import re
from jedi.evaluate.cache import memoize_default from jedi.evaluate.cache import memoize_default
from jedi.parser.user_context import UserContextParser from jedi.parser import Parser
DOCSTRING_PARAM_PATTERNS = [ DOCSTRING_PARAM_PATTERNS = [
r'\s*:type\s+%s:\s*([^\n]+)', # Sphinx r'\s*:type\s+%s:\s*([^\n]+)', # Sphinx
@@ -37,7 +37,7 @@ def follow_param(evaluator, param):
func = param.parent_function func = param.parent_function
# print func, param, param.parent_function # print func, param, param.parent_function
param_str = _search_param_in_docstr(func.docstr, str(param.get_name())) 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: if param_str is not None:
@@ -47,12 +47,13 @@ def follow_param(evaluator, param):
param_str = 'import %s\n%s' % ( param_str = 'import %s\n%s' % (
param_str.rsplit('.', 1)[0], param_str.rsplit('.', 1)[0],
param_str) param_str)
user_position = (2, 0) position = (2, 0)
p = UserContextParser(param_str, None, user_position, no_docstr=True) p = Parser(param_str, no_docstr=True)
if p.user_stmt() is None: stmt = p.module.get_statement_for_position(position)
if stmt is None:
return [] return []
return evaluator.eval_statement(p.user_stmt()) return evaluator.eval_statement(stmt)
return [] return []
@@ -115,8 +116,9 @@ def find_return_types(evaluator, func):
if not type_str: if not type_str:
return [] return []
p = UserContextParser(type_str, None, (1, 0), no_docstr=True) p = Parser(type_str, None, no_docstr=True)
if p.user_stmt() is None: stmt = p.module.get_statement_for_position((1, 0))
if stmt is None:
return [] return []
p.user_stmt().parent = func stmt.parent = func
return list(evaluator.eval_statement(p.user_stmt())) return list(evaluator.eval_statement(stmt))

View File

@@ -3,7 +3,7 @@ import os
import sys import sys
from jedi import cache from jedi import cache
from jedi.parser import tokenize, Parser from jedi.parser import tokenize
from jedi.parser.fast import FastParser from jedi.parser.fast import FastParser
from jedi.parser import representation from jedi.parser import representation
from jedi import debug from jedi import debug
@@ -181,22 +181,18 @@ class UserContext(object):
class UserContextParser(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._source = source
self._path = path and os.path.abspath(path) self._path = path and os.path.abspath(path)
self._position = position self._position = position
self._user_context = user_context self._user_context = user_context
self._no_docstr = no_docstr
@cache.underscore_memoization @cache.underscore_memoization
def _parser(self): def _parser(self):
cache.invalidate_star_import_cache(self._path) cache.invalidate_star_import_cache(self._path)
if self._no_docstr: parser = FastParser(self._source, self._path)
parser = Parser(self._source, self._path, no_docstr=self._no_docstr) # Don't pickle that module, because the main module is changing quickly
else: 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 return parser
@cache.underscore_memoization @cache.underscore_memoization