mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-15 18:17:07 +08:00
First changes to eventually replace Name by NamePart.
This commit is contained in:
@@ -133,6 +133,12 @@ class Parser(object):
|
|||||||
n = pr.Name(self.module, names, first_pos, end_pos) if names else None
|
n = pr.Name(self.module, names, first_pos, end_pos) if names else None
|
||||||
return n, tok
|
return n, tok
|
||||||
|
|
||||||
|
def _parse_name(self, pre_used_token=None):
|
||||||
|
tok = next(self._gen) if pre_used_token is None else pre_used_token
|
||||||
|
if tok.type != tokenize.NAME:
|
||||||
|
return None
|
||||||
|
return pr.NamePart(self.module, tok.string, None, tok.start_pos)
|
||||||
|
|
||||||
def _parse_import_list(self):
|
def _parse_import_list(self):
|
||||||
"""
|
"""
|
||||||
The parser for the imports. Unlike the class and function parse
|
The parser for the imports. Unlike the class and function parse
|
||||||
@@ -224,8 +230,7 @@ class Parser(object):
|
|||||||
if tok.type != tokenize.NAME:
|
if tok.type != tokenize.NAME:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
fname = pr.Name(self.module, [(tok.string, tok.start_pos)], tok.start_pos,
|
fname = self._parse_name(tok)
|
||||||
tok.end_pos)
|
|
||||||
|
|
||||||
tok = next(self._gen)
|
tok = next(self._gen)
|
||||||
if tok.string != '(':
|
if tok.string != '(':
|
||||||
@@ -246,7 +251,7 @@ class Parser(object):
|
|||||||
if colon.string != ':':
|
if colon.string != ':':
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# because of 2 line func param definitions
|
# Because of 2 line func param definitions
|
||||||
return pr.Function(self.module, fname, params, first_pos, annotation)
|
return pr.Function(self.module, fname, params, first_pos, annotation)
|
||||||
|
|
||||||
def _parse_class(self):
|
def _parse_class(self):
|
||||||
@@ -264,8 +269,7 @@ class Parser(object):
|
|||||||
cname.start_pos[0], tokenize.tok_name[cname.type], cname.string)
|
cname.start_pos[0], tokenize.tok_name[cname.type], cname.string)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
cname = pr.Name(self.module, [(cname.string, cname.start_pos)],
|
cname = self._parse_name(cname)
|
||||||
cname.start_pos, cname.end_pos)
|
|
||||||
|
|
||||||
superclasses = []
|
superclasses = []
|
||||||
_next = next(self._gen)
|
_next = next(self._gen)
|
||||||
|
|||||||
@@ -1488,7 +1488,7 @@ class NamePart(object):
|
|||||||
return self._string
|
return self._string
|
||||||
|
|
||||||
def get_definition(self):
|
def get_definition(self):
|
||||||
return self.parent.get_definition()
|
return self.get_parent_until((ExprStmt, IsScope, Import))
|
||||||
|
|
||||||
def get_parent_until(self, *args, **kwargs):
|
def get_parent_until(self, *args, **kwargs):
|
||||||
return self.parent.get_parent_until(*args, **kwargs)
|
return self.parent.get_parent_until(*args, **kwargs)
|
||||||
|
|||||||
Reference in New Issue
Block a user