mirror of https://github.com/python/cpython
bpo-29776: Use decorator syntax for properties. (#585)
This commit is contained in:
parent
c85a26628c
commit
bdf6b910f9
|
@ -1674,13 +1674,13 @@ class Decimal(object):
|
|||
|
||||
__trunc__ = __int__
|
||||
|
||||
@property
|
||||
def real(self):
|
||||
return self
|
||||
real = property(real)
|
||||
|
||||
@property
|
||||
def imag(self):
|
||||
return Decimal(0)
|
||||
imag = property(imag)
|
||||
|
||||
def conjugate(self):
|
||||
return self
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -465,8 +465,13 @@ class Listener(object):
|
|||
self._listener = None
|
||||
listener.close()
|
||||
|
||||
address = property(lambda self: self._listener._address)
|
||||
last_accepted = property(lambda self: self._listener._last_accepted)
|
||||
@property
|
||||
def address(self):
|
||||
return self._listener._address
|
||||
|
||||
@property
|
||||
def last_accepted(self):
|
||||
return self._listener._last_accepted
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
|
|
@ -98,11 +98,15 @@ class Value(object):
|
|||
def __init__(self, typecode, value, lock=True):
|
||||
self._typecode = typecode
|
||||
self._value = value
|
||||
def _get(self):
|
||||
|
||||
@property
|
||||
def value(self):
|
||||
return self._value
|
||||
def _set(self, value):
|
||||
|
||||
@value.setter
|
||||
def value(self, value):
|
||||
self._value = value
|
||||
value = property(_get, _set)
|
||||
|
||||
def __repr__(self):
|
||||
return '<%s(%r, %r)>'%(type(self).__name__,self._typecode,self._value)
|
||||
|
||||
|
|
|
@ -26,7 +26,9 @@ class Listener(object):
|
|||
def close(self):
|
||||
self._backlog_queue = None
|
||||
|
||||
address = property(lambda self: self._backlog_queue)
|
||||
@property
|
||||
def address(self):
|
||||
return self._backlog_queue
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
|
|
@ -628,7 +628,9 @@ class BaseManager(object):
|
|||
except KeyError:
|
||||
pass
|
||||
|
||||
address = property(lambda self: self._address)
|
||||
@property
|
||||
def address(self):
|
||||
return self._address
|
||||
|
||||
@classmethod
|
||||
def register(cls, typeid, callable=None, proxytype=None, exposed=None,
|
||||
|
|
|
@ -1868,8 +1868,13 @@ class Helper:
|
|||
self._input = input
|
||||
self._output = output
|
||||
|
||||
input = property(lambda self: self._input or sys.stdin)
|
||||
output = property(lambda self: self._output or sys.stdout)
|
||||
@property
|
||||
def input(self):
|
||||
return self._input or sys.stdin
|
||||
|
||||
@property
|
||||
def output(self):
|
||||
return self._output or sys.stdout
|
||||
|
||||
def __repr__(self):
|
||||
if inspect.stack()[1][3] == '?':
|
||||
|
|
|
@ -761,17 +761,21 @@ class TarInfo(object):
|
|||
|
||||
# In pax headers the "name" and "linkname" field are called
|
||||
# "path" and "linkpath".
|
||||
def _getpath(self):
|
||||
@property
|
||||
def path(self):
|
||||
return self.name
|
||||
def _setpath(self, name):
|
||||
self.name = name
|
||||
path = property(_getpath, _setpath)
|
||||
|
||||
def _getlinkpath(self):
|
||||
@path.setter
|
||||
def path(self, name):
|
||||
self.name = name
|
||||
|
||||
@property
|
||||
def linkpath(self):
|
||||
return self.linkname
|
||||
def _setlinkpath(self, linkname):
|
||||
|
||||
@linkpath.setter
|
||||
def linkpath(self, linkname):
|
||||
self.linkname = linkname
|
||||
linkpath = property(_getlinkpath, _setlinkpath)
|
||||
|
||||
def __repr__(self):
|
||||
return "<%s %r at %#x>" % (self.__class__.__name__,self.name,id(self))
|
||||
|
|
|
@ -160,7 +160,7 @@ class PyclbrTest(TestCase):
|
|||
cm('aifc', ignore=('openfp', '_aifc_params')) # set with = in module
|
||||
cm('sre_parse', ignore=('dump', 'groups', 'pos')) # from sre_constants import *; property
|
||||
cm('pdb')
|
||||
cm('pydoc')
|
||||
cm('pydoc', ignore=('input', 'output',)) # properties
|
||||
|
||||
# Tests for modules inside packages
|
||||
cm('email.parser')
|
||||
|
|
|
@ -1577,20 +1577,17 @@ class LabeledScale(Frame):
|
|||
self.label['text'] = newval
|
||||
self.after_idle(adjust_label)
|
||||
|
||||
|
||||
def _get_value(self):
|
||||
@property
|
||||
def value(self):
|
||||
"""Return current scale value."""
|
||||
return self._variable.get()
|
||||
|
||||
|
||||
def _set_value(self, val):
|
||||
@value.setter
|
||||
def value(self, val):
|
||||
"""Set new scale value."""
|
||||
self._variable.set(val)
|
||||
|
||||
|
||||
value = property(_get_value, _set_value)
|
||||
|
||||
|
||||
class OptionMenu(Menubutton):
|
||||
"""Themed OptionMenu, based after tkinter's OptionMenu, which allows
|
||||
the user to select a value from a menu."""
|
||||
|
|
Loading…
Reference in New Issue