diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 9da62f6..9c9e91a 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -9,6 +9,7 @@ Unreleased (XXXX-XX-XX) - Dropped Support for Python 2.7, 3.4, 3.5 - It's possible to use ``pathlib.Path`` objects now in the API - The stubs are gone, we are now using annotations +- ``namedexpr_test`` nodes are now a proper class called ``NamedExpr`` - A lot of smaller refactorings 0.7.1 (2020-07-24) diff --git a/parso/python/parser.py b/parso/python/parser.py index 5cc3ced..da92d44 100644 --- a/parso/python/parser.py +++ b/parso/python/parser.py @@ -46,6 +46,7 @@ class Parser(BaseParser): 'decorator': tree.Decorator, 'lambdef': tree.Lambda, 'lambdef_nocond': tree.Lambda, + 'namedexpr_test': tree.NamedExpr, } default_node = tree.PythonNode diff --git a/parso/python/tree.py b/parso/python/tree.py index 60696d0..55b8058 100644 --- a/parso/python/tree.py +++ b/parso/python/tree.py @@ -63,7 +63,7 @@ _FUNC_CONTAINERS = set( _GET_DEFINITION_TYPES = set([ 'expr_stmt', 'sync_comp_for', 'with_stmt', 'for_stmt', 'import_name', - 'import_from', 'param', 'del_stmt', + 'import_from', 'param', 'del_stmt', 'namedexpr_test', ]) _IMPORTS = set(['import_name', 'import_from']) @@ -231,8 +231,6 @@ class Name(_LeafWithoutNewlines): while node is not None: if node.type == 'suite': return None - if node.type == 'namedexpr_test': - return node.children[0] if node.type in _GET_DEFINITION_TYPES: if self in node.get_defined_names(include_setitem): return node @@ -1066,6 +1064,13 @@ class ExprStmt(PythonBaseNode, DocstringMixin): yield from self.children[3::2] +class NamedExpr(PythonBaseNode): + type = 'namedexpr_test' + + def get_defined_names(self, include_setitem=False): + return _defined_names(self.children[0], include_setitem) + + class Param(PythonBaseNode): """ It's a helper class that makes business logic with params much easier. The