mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-08 21:54:54 +08:00
Fix an issue in the diff parser
Forgot to check for functions/classes that were part of a decorator/async func. Fixes https://github.com/davidhalter/jedi/issues/1132
This commit is contained in:
@@ -570,7 +570,9 @@ class _NodesStack(object):
|
|||||||
self._tos = _NodesStackNode(tree_node, self._tos)
|
self._tos = _NodesStackNode(tree_node, self._tos)
|
||||||
self._tos.add(list(tree_node.children))
|
self._tos.add(list(tree_node.children))
|
||||||
self._update_tos(tree_node.children[-1])
|
self._update_tos(tree_node.children[-1])
|
||||||
elif tree_node.type in ('classdef', 'funcdef'):
|
elif tree_node.type in ('decorated', 'classdef', 'funcdef',
|
||||||
|
'async_funcdef') \
|
||||||
|
or tree_node.type == 'async_stmt' and tree_node.children[0].type == 'funcdef':
|
||||||
self._update_tos(tree_node.children[-1])
|
self._update_tos(tree_node.children[-1])
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
|
|||||||
@@ -507,3 +507,22 @@ def test_endmarker_newline(differ):
|
|||||||
def test_newlines_at_end(differ):
|
def test_newlines_at_end(differ):
|
||||||
differ.initialize('a\n\n')
|
differ.initialize('a\n\n')
|
||||||
differ.parse('a\n', copies=1)
|
differ.parse('a\n', copies=1)
|
||||||
|
|
||||||
|
|
||||||
|
def test_end_newline_with_decorator(differ):
|
||||||
|
code = dedent('''\
|
||||||
|
@staticmethod
|
||||||
|
def spam():
|
||||||
|
import json
|
||||||
|
json.l''')
|
||||||
|
|
||||||
|
differ.initialize(code)
|
||||||
|
module = differ.parse(code + '\n', copies=0)
|
||||||
|
decorated, endmarker = module.children
|
||||||
|
assert decorated.type == 'decorated'
|
||||||
|
decorator, func = decorated.children
|
||||||
|
suite = func.children[-1]
|
||||||
|
assert suite.type == 'suite'
|
||||||
|
newline, first_stmt, second_stmt = suite.children
|
||||||
|
assert first_stmt.get_code() == ' import json\n'
|
||||||
|
assert second_stmt.get_code() == ' json.l\n'
|
||||||
|
|||||||
Reference in New Issue
Block a user