mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-29776: Use decorator syntax for properties. (#585)
This commit is contained in:
parent
c85a26628c
commit
bdf6b910f9
10 changed files with 53 additions and 34 deletions
|
@ -271,7 +271,8 @@ class Node(Base):
|
|||
for child in self.children:
|
||||
yield from child.pre_order()
|
||||
|
||||
def _prefix_getter(self):
|
||||
@property
|
||||
def prefix(self):
|
||||
"""
|
||||
The whitespace and comments preceding this node in the input.
|
||||
"""
|
||||
|
@ -279,12 +280,11 @@ class Node(Base):
|
|||
return ""
|
||||
return self.children[0].prefix
|
||||
|
||||
def _prefix_setter(self, prefix):
|
||||
@prefix.setter
|
||||
def prefix(self, prefix):
|
||||
if self.children:
|
||||
self.children[0].prefix = prefix
|
||||
|
||||
prefix = property(_prefix_getter, _prefix_setter)
|
||||
|
||||
def set_child(self, i, child):
|
||||
"""
|
||||
Equivalent to 'node.children[i] = child'. This method also sets the
|
||||
|
@ -380,18 +380,18 @@ class Leaf(Base):
|
|||
"""Return a pre-order iterator for the tree."""
|
||||
yield self
|
||||
|
||||
def _prefix_getter(self):
|
||||
@property
|
||||
def prefix(self):
|
||||
"""
|
||||
The whitespace and comments preceding this token in the input.
|
||||
"""
|
||||
return self._prefix
|
||||
|
||||
def _prefix_setter(self, prefix):
|
||||
@prefix.setter
|
||||
def prefix(self, prefix):
|
||||
self.changed()
|
||||
self._prefix = prefix
|
||||
|
||||
prefix = property(_prefix_getter, _prefix_setter)
|
||||
|
||||
def convert(gr, raw_node):
|
||||
"""
|
||||
Convert raw node information to a Node or Leaf instance.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue