1
0
forked from VimPlug/jedi

Merge branch 'remove_names_dicts' into diff

This commit is contained in:
Dave Halter
2016-09-11 13:24:11 +02:00
8 changed files with 26 additions and 51 deletions

View File

@@ -172,6 +172,12 @@ class Parser(object):
try:
new_node = Parser.AST_MAPPING[symbol](children)
except KeyError:
if symbol == 'suite':
# We don't want the INDENT/DEDENT in our parser tree. Those
# leaves are just cancer. They are virtual leaves and not real
# ones and therefore have pseudo start/end positions and no
# prefixes. Just ignore them.
children = [children[0]] + children[2:-1]
new_node = pt.Node(symbol, children)
# We need to check raw_node always, because the same node can be
@@ -220,10 +226,6 @@ class Parser(object):
return pt.Number(self.position_modifier, value, start_pos, prefix)
elif type == NEWLINE:
return pt.Newline(self.position_modifier, value, start_pos, prefix)
elif type == INDENT:
return pt.Indent(self.position_modifier, value, start_pos, prefix)
elif type == DEDENT:
return pt.Dedent(self.position_modifier, value, start_pos, prefix)
elif type == ENDMARKER:
return pt.EndMarker(self.position_modifier, value, start_pos, prefix)
else:

View File

@@ -87,7 +87,7 @@ class DocstringMixin(object):
elif isinstance(self, ClassOrFunc):
node = self.children[self.children.index(':') + 1]
if is_node(node, 'suite'): # Normally a suite
node = node.children[2] # -> NEWLINE INDENT stmt
node = node.children[1] # -> NEWLINE stmt
else: # ExprStmt
simple_stmt = self.parent
c = simple_stmt.parent.children
@@ -160,7 +160,7 @@ class Base(object):
return scope
def get_definition(self):
if self.type in ('newline', 'dedent', 'indent', 'endmarker'):
if self.type in ('newline', 'endmarker'):
raise ValueError('Cannot get the indentation of whitespace or indentation.')
scope = self
while scope.parent is not None:
@@ -307,11 +307,7 @@ class Leaf(Base):
def get_start_pos_of_prefix(self):
try:
previous_leaf = self
while True:
previous_leaf = previous_leaf.get_previous_leaf()
if previous_leaf.type not in ('indent', 'dedent'):
return previous_leaf.end_pos
return self.get_previous_leaf().end_pos
except IndexError:
return 1, 0 # It's the first leaf.
@@ -444,16 +440,6 @@ class String(Literal):
__slots__ = ()
class Indent(Leaf):
type = 'indent'
__slots__ = ()
class Dedent(Leaf):
type = 'dedent'
__slots__ = ()
class Operator(Leaf):
type = 'operator'
__slots__ = ()
@@ -568,10 +554,6 @@ class BaseNode(Base):
try:
return c.get_leaf_for_position(position, include_prefixes)
except AttributeError:
while c.type in ('indent', 'dedent'):
# We'd rather not have indents and dedents as a leaf,
# because they don't contain indentation information.
c = c.get_next_leaf()
return c
return None