1
0
forked from VimPlug/jedi

* Replaced token tuple with token class

* Fixed PEP8 where I read code
This commit is contained in:
Jean-Louis Fuchs
2013-12-05 23:34:20 +01:00
parent 099fe4eeb3
commit 989e12e8a7
4 changed files with 34 additions and 14 deletions

View File

@@ -220,7 +220,7 @@ def save_module(path, name, parser, pickling=True):
class _ModulePickling(object):
version = 4
version = 5
"""
Version number (integer) for file system cache.

View File

@@ -146,8 +146,13 @@ class NoErrorTokenizer(object):
if self.is_fast_parser \
and self.previous[0] in (tokenize.INDENT, tokenize.NL, None,
tokenize.NEWLINE, tokenize.DEDENT) \
and c[0] not in (tokenize.COMMENT, tokenize.INDENT,
tokenize.NL, tokenize.NEWLINE, tokenize.DEDENT):
and c[0] not in (
tokenize.COMMENT,
tokenize.INDENT,
tokenize.NL,
tokenize.NEWLINE,
tokenize.DEDENT
):
# print c, tokenize.tok_name[c[0]]
tok = c[1]

View File

@@ -24,6 +24,7 @@ from jedi._compatibility import next, StringIO
from jedi import debug
from jedi import common
from jedi.parser import representation as pr
from jedi.parser import token as token_pr
class Parser(object):
@@ -271,8 +272,11 @@ class Parser(object):
first_pos = self.start_pos
token_type, cname = self.next()
if token_type != tokenize.NAME:
debug.warning("class: syntax err, token is not a name@%s (%s: %s)"
% (self.start_pos[0], tokenize.tok_name[token_type], cname))
debug.warning(
"class: syntax err, token is not a name@%s (%s: %s)" % (
self.start_pos[0], tokenize.tok_name[token_type], cname
)
)
return None
cname = pr.Name(self.module, [(cname, self.start_pos)], self.start_pos,
@@ -345,11 +349,17 @@ class Parser(object):
or tok in breaks and level <= 0):
try:
# print 'parse_stmt', tok, tokenize.tok_name[token_type]
tok_list.append(self._current + (self.start_pos,))
tok_list.append(
token_pr.Token.from_tuple(
self._current + (self.start_pos,)
)
)
if tok == 'as':
token_type, tok = self.next()
if token_type == tokenize.NAME:
n, token_type, tok = self._parse_dot_name(self._current)
n, token_type, tok = self._parse_dot_name(
self._current
)
if n:
set_vars.append(n)
as_names.append(n)
@@ -396,7 +406,6 @@ class Parser(object):
self._scope.statements[-1].add_docstr(first_tok[1])
return None, tok
stmt = stmt_class(self.module, tok_list, first_pos, self.end_pos,
as_names=as_names,
names_are_set_vars=names_are_set_vars)
@@ -435,9 +444,11 @@ class Parser(object):
s = s.parent
raise
if self.user_position and (self.start_pos[0] == self.user_position[0]
if self.user_position and (
self.start_pos[0] == self.user_position[0]
or self.user_scope is None
and self.start_pos[0] >= self.user_position[0]):
and self.start_pos[0] >= self.user_position[0]
):
debug.dbg('user scope found [%s] = %s' %
(self.parserline.replace('\n', ''), repr(self._scope)))
self.user_scope = self._scope
@@ -489,8 +500,9 @@ class Parser(object):
and not isinstance(self._scope, pr.SubModule):
self._scope = self.module
use_as_parent_scope = self.top_module if isinstance(self._scope,
pr.SubModule) else self._scope
use_as_parent_scope = self.top_module if isinstance(
self._scope, pr.SubModule
) else self._scope
first_pos = self.start_pos
if tok == 'def':
func = self._parse_function()

View File

@@ -1,6 +1,7 @@
from jedi.parser import Parser
from jedi.parser import representation as pr
def test_user_statement_on_import():
"""github #285"""
s = "from datetime import (\n" \
@@ -9,7 +10,7 @@ def test_user_statement_on_import():
for pos in [(2, 1), (2, 4)]:
u = Parser(s, user_position=pos).user_stmt
assert isinstance(u, pr.Import)
assert u.defunct == False
assert u.defunct is False
assert [str(n) for n in u.get_defined_names()] == ['time']
@@ -47,6 +48,7 @@ class TestCallAndName():
assert isinstance(literal, pr.String)
assert literal.value == 'hello'
class TestSubscopes():
def get_sub(self, source):
return Parser(source).module.subscopes[0]
@@ -62,6 +64,7 @@ class TestSubscopes():
assert name.end_pos == (1, len('def foo'))
assert str(name) == 'foo'
class TestImports():
def get_import(self, source):
return Parser(source).module.imports[0]