mirror of
https://github.com/davidhalter/parso.git
synced 2026-01-17 00:25:21 +08:00
Make namedexpr_test a proper NamedExpr class
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user