Remove more python 2 specific code

This commit is contained in:
Dave Halter
2020-07-25 01:31:19 +02:00
parent 4c09583072
commit d7ab138864
2 changed files with 3 additions and 20 deletions

View File

@@ -512,9 +512,7 @@ def tokenize_lines(lines, version_info, start_pos=(1, 0), indents=None, is_first
yield from _split_illegal_unicode_name(token, spos, prefix) yield from _split_illegal_unicode_name(token, spos, prefix)
elif initial in '\r\n': elif initial in '\r\n':
if any(not f.allow_multiline() for f in fstring_stack): if any(not f.allow_multiline() for f in fstring_stack):
# Would use fstring_stack.clear, but that's not available fstring_stack.clear()
# in Python 2.
fstring_stack[:] = []
if not new_line and paren_level == 0 and not fstring_stack: if not new_line and paren_level == 0 and not fstring_stack:
yield PythonToken(NEWLINE, token, spos, prefix) yield PythonToken(NEWLINE, token, spos, prefix)

View File

@@ -1,5 +1,5 @@
""" """
This is the syntax tree for Python syntaxes (2 & 3). The classes represent This is the syntax tree for Python 3 syntaxes. The classes represent
syntax elements like functions and imports. syntax elements like functions and imports.
All of the nodes can be traced back to the `Python grammar file All of the nodes can be traced back to the `Python grammar file
@@ -224,9 +224,6 @@ class Name(_LeafWithoutNewlines):
return None return None
if type_ == 'except_clause': if type_ == 'except_clause':
# TODO in Python 2 this doesn't work correctly. See grammar file.
# I think we'll just let it be. Python 2 will be gone in a few
# years.
if self.get_previous_sibling() == 'as': if self.get_previous_sibling() == 'as':
return node.parent # The try_stmt. return node.parent # The try_stmt.
return None return None
@@ -512,24 +509,13 @@ def _create_params(parent, argslist_list):
You could also say that this function replaces the argslist node with a You could also say that this function replaces the argslist node with a
list of Param objects. list of Param objects.
""" """
def check_python2_nested_param(node):
"""
Python 2 allows params to look like ``def x(a, (b, c))``, which is
basically a way of unpacking tuples in params. Python 3 has ditched
this behavior. Jedi currently just ignores those constructs.
"""
return node.type == 'fpdef' and node.children[0] == '('
try: try:
first = argslist_list[0] first = argslist_list[0]
except IndexError: except IndexError:
return [] return []
if first.type in ('name', 'fpdef'): if first.type in ('name', 'fpdef'):
if check_python2_nested_param(first): return [Param([first], parent)]
return [first]
else:
return [Param([first], parent)]
elif first == '*': elif first == '*':
return [first] return [first]
else: # argslist is a `typedargslist` or a `varargslist`. else: # argslist is a `typedargslist` or a `varargslist`.
@@ -547,7 +533,6 @@ def _create_params(parent, argslist_list):
if param_children[0] == '*' \ if param_children[0] == '*' \
and (len(param_children) == 1 and (len(param_children) == 1
or param_children[1] == ',') \ or param_children[1] == ',') \
or check_python2_nested_param(param_children[0]) \
or param_children[0] == '/': or param_children[0] == '/':
for p in param_children: for p in param_children:
p.parent = parent p.parent = parent