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__
|
__trunc__ = __int__
|
||||||
|
|
||||||
|
@property
|
||||||
def real(self):
|
def real(self):
|
||||||
return self
|
return self
|
||||||
real = property(real)
|
|
||||||
|
|
||||||
|
@property
|
||||||
def imag(self):
|
def imag(self):
|
||||||
return Decimal(0)
|
return Decimal(0)
|
||||||
imag = property(imag)
|
|
||||||
|
|
||||||
def conjugate(self):
|
def conjugate(self):
|
||||||
return self
|
return self
|
||||||
|
@ -271,7 +271,8 @@ class Node(Base):
|
|||||||
for child in self.children:
|
for child in self.children:
|
||||||
yield from child.pre_order()
|
yield from child.pre_order()
|
||||||
|
|
||||||
def _prefix_getter(self):
|
@property
|
||||||
|
def prefix(self):
|
||||||
"""
|
"""
|
||||||
The whitespace and comments preceding this node in the input.
|
The whitespace and comments preceding this node in the input.
|
||||||
"""
|
"""
|
||||||
@ -279,12 +280,11 @@ class Node(Base):
|
|||||||
return ""
|
return ""
|
||||||
return self.children[0].prefix
|
return self.children[0].prefix
|
||||||
|
|
||||||
def _prefix_setter(self, prefix):
|
@prefix.setter
|
||||||
|
def prefix(self, prefix):
|
||||||
if self.children:
|
if self.children:
|
||||||
self.children[0].prefix = prefix
|
self.children[0].prefix = prefix
|
||||||
|
|
||||||
prefix = property(_prefix_getter, _prefix_setter)
|
|
||||||
|
|
||||||
def set_child(self, i, child):
|
def set_child(self, i, child):
|
||||||
"""
|
"""
|
||||||
Equivalent to 'node.children[i] = child'. This method also sets the
|
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."""
|
"""Return a pre-order iterator for the tree."""
|
||||||
yield self
|
yield self
|
||||||
|
|
||||||
def _prefix_getter(self):
|
@property
|
||||||
|
def prefix(self):
|
||||||
"""
|
"""
|
||||||
The whitespace and comments preceding this token in the input.
|
The whitespace and comments preceding this token in the input.
|
||||||
"""
|
"""
|
||||||
return self._prefix
|
return self._prefix
|
||||||
|
|
||||||
def _prefix_setter(self, prefix):
|
@prefix.setter
|
||||||
|
def prefix(self, prefix):
|
||||||
self.changed()
|
self.changed()
|
||||||
self._prefix = prefix
|
self._prefix = prefix
|
||||||
|
|
||||||
prefix = property(_prefix_getter, _prefix_setter)
|
|
||||||
|
|
||||||
def convert(gr, raw_node):
|
def convert(gr, raw_node):
|
||||||
"""
|
"""
|
||||||
Convert raw node information to a Node or Leaf instance.
|
Convert raw node information to a Node or Leaf instance.
|
||||||
|
@ -465,8 +465,13 @@ class Listener(object):
|
|||||||
self._listener = None
|
self._listener = None
|
||||||
listener.close()
|
listener.close()
|
||||||
|
|
||||||
address = property(lambda self: self._listener._address)
|
@property
|
||||||
last_accepted = property(lambda self: self._listener._last_accepted)
|
def address(self):
|
||||||
|
return self._listener._address
|
||||||
|
|
||||||
|
@property
|
||||||
|
def last_accepted(self):
|
||||||
|
return self._listener._last_accepted
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
return self
|
return self
|
||||||
|
@ -98,11 +98,15 @@ class Value(object):
|
|||||||
def __init__(self, typecode, value, lock=True):
|
def __init__(self, typecode, value, lock=True):
|
||||||
self._typecode = typecode
|
self._typecode = typecode
|
||||||
self._value = value
|
self._value = value
|
||||||
def _get(self):
|
|
||||||
|
@property
|
||||||
|
def value(self):
|
||||||
return self._value
|
return self._value
|
||||||
def _set(self, value):
|
|
||||||
|
@value.setter
|
||||||
|
def value(self, value):
|
||||||
self._value = value
|
self._value = value
|
||||||
value = property(_get, _set)
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<%s(%r, %r)>'%(type(self).__name__,self._typecode,self._value)
|
return '<%s(%r, %r)>'%(type(self).__name__,self._typecode,self._value)
|
||||||
|
|
||||||
|
@ -26,7 +26,9 @@ class Listener(object):
|
|||||||
def close(self):
|
def close(self):
|
||||||
self._backlog_queue = None
|
self._backlog_queue = None
|
||||||
|
|
||||||
address = property(lambda self: self._backlog_queue)
|
@property
|
||||||
|
def address(self):
|
||||||
|
return self._backlog_queue
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
return self
|
return self
|
||||||
|
@ -628,7 +628,9 @@ class BaseManager(object):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
address = property(lambda self: self._address)
|
@property
|
||||||
|
def address(self):
|
||||||
|
return self._address
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def register(cls, typeid, callable=None, proxytype=None, exposed=None,
|
def register(cls, typeid, callable=None, proxytype=None, exposed=None,
|
||||||
|
@ -1868,8 +1868,13 @@ class Helper:
|
|||||||
self._input = input
|
self._input = input
|
||||||
self._output = output
|
self._output = output
|
||||||
|
|
||||||
input = property(lambda self: self._input or sys.stdin)
|
@property
|
||||||
output = property(lambda self: self._output or sys.stdout)
|
def input(self):
|
||||||
|
return self._input or sys.stdin
|
||||||
|
|
||||||
|
@property
|
||||||
|
def output(self):
|
||||||
|
return self._output or sys.stdout
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
if inspect.stack()[1][3] == '?':
|
if inspect.stack()[1][3] == '?':
|
||||||
|
@ -761,17 +761,21 @@ class TarInfo(object):
|
|||||||
|
|
||||||
# In pax headers the "name" and "linkname" field are called
|
# In pax headers the "name" and "linkname" field are called
|
||||||
# "path" and "linkpath".
|
# "path" and "linkpath".
|
||||||
def _getpath(self):
|
@property
|
||||||
|
def path(self):
|
||||||
return self.name
|
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
|
return self.linkname
|
||||||
def _setlinkpath(self, linkname):
|
|
||||||
|
@linkpath.setter
|
||||||
|
def linkpath(self, linkname):
|
||||||
self.linkname = linkname
|
self.linkname = linkname
|
||||||
linkpath = property(_getlinkpath, _setlinkpath)
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<%s %r at %#x>" % (self.__class__.__name__,self.name,id(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('aifc', ignore=('openfp', '_aifc_params')) # set with = in module
|
||||||
cm('sre_parse', ignore=('dump', 'groups', 'pos')) # from sre_constants import *; property
|
cm('sre_parse', ignore=('dump', 'groups', 'pos')) # from sre_constants import *; property
|
||||||
cm('pdb')
|
cm('pdb')
|
||||||
cm('pydoc')
|
cm('pydoc', ignore=('input', 'output',)) # properties
|
||||||
|
|
||||||
# Tests for modules inside packages
|
# Tests for modules inside packages
|
||||||
cm('email.parser')
|
cm('email.parser')
|
||||||
|
@ -1577,20 +1577,17 @@ class LabeledScale(Frame):
|
|||||||
self.label['text'] = newval
|
self.label['text'] = newval
|
||||||
self.after_idle(adjust_label)
|
self.after_idle(adjust_label)
|
||||||
|
|
||||||
|
@property
|
||||||
def _get_value(self):
|
def value(self):
|
||||||
"""Return current scale value."""
|
"""Return current scale value."""
|
||||||
return self._variable.get()
|
return self._variable.get()
|
||||||
|
|
||||||
|
@value.setter
|
||||||
def _set_value(self, val):
|
def value(self, val):
|
||||||
"""Set new scale value."""
|
"""Set new scale value."""
|
||||||
self._variable.set(val)
|
self._variable.set(val)
|
||||||
|
|
||||||
|
|
||||||
value = property(_get_value, _set_value)
|
|
||||||
|
|
||||||
|
|
||||||
class OptionMenu(Menubutton):
|
class OptionMenu(Menubutton):
|
||||||
"""Themed OptionMenu, based after tkinter's OptionMenu, which allows
|
"""Themed OptionMenu, based after tkinter's OptionMenu, which allows
|
||||||
the user to select a value from a menu."""
|
the user to select a value from a menu."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user