summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-03-19 08:40:32 +0200
committerGitHub <noreply@github.com>2017-03-19 08:40:32 +0200
commitbdf6b910f9ea75609caee498a975af03b6d23f67 (patch)
treeac69902aaaeb9c2e0578181e911a36af201ea1a0
parentc85a26628ceb9624c96c3064e8b99033c026d8a3 (diff)
downloadcpython-git-bdf6b910f9ea75609caee498a975af03b6d23f67.tar.gz
bpo-29776: Use decorator syntax for properties. (#585)
-rw-r--r--Lib/_pydecimal.py4
-rw-r--r--Lib/lib2to3/pytree.py16
-rw-r--r--Lib/multiprocessing/connection.py9
-rw-r--r--Lib/multiprocessing/dummy/__init__.py10
-rw-r--r--Lib/multiprocessing/dummy/connection.py4
-rw-r--r--Lib/multiprocessing/managers.py4
-rw-r--r--Lib/pydoc.py9
-rwxr-xr-xLib/tarfile.py16
-rw-r--r--Lib/test/test_pyclbr.py2
-rw-r--r--Lib/tkinter/ttk.py11
10 files changed, 52 insertions, 33 deletions
diff --git a/Lib/_pydecimal.py b/Lib/_pydecimal.py
index 0fa152c2a6..edabf72aa7 100644
--- a/Lib/_pydecimal.py
+++ b/Lib/_pydecimal.py
@@ -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
diff --git a/Lib/lib2to3/pytree.py b/Lib/lib2to3/pytree.py
index c425fe6827..2a6ef2ef52 100644
--- a/Lib/lib2to3/pytree.py
+++ b/Lib/lib2to3/pytree.py
@@ -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.
diff --git a/Lib/multiprocessing/connection.py b/Lib/multiprocessing/connection.py
index d49e8f0d32..ba9b17cee1 100644
--- a/Lib/multiprocessing/connection.py
+++ b/Lib/multiprocessing/connection.py
@@ -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
diff --git a/Lib/multiprocessing/dummy/__init__.py b/Lib/multiprocessing/dummy/__init__.py
index 1abea64419..cbb7f4909c 100644
--- a/Lib/multiprocessing/dummy/__init__.py
+++ b/Lib/multiprocessing/dummy/__init__.py
@@ -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)
diff --git a/Lib/multiprocessing/dummy/connection.py b/Lib/multiprocessing/dummy/connection.py
index 19843751c0..f0ce320fcf 100644
--- a/Lib/multiprocessing/dummy/connection.py
+++ b/Lib/multiprocessing/dummy/connection.py
@@ -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
diff --git a/Lib/multiprocessing/managers.py b/Lib/multiprocessing/managers.py
index b9ce84b2d8..43dd02a5a3 100644
--- a/Lib/multiprocessing/managers.py
+++ b/Lib/multiprocessing/managers.py
@@ -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,
diff --git a/Lib/pydoc.py b/Lib/pydoc.py
index 49555405c5..376c4459fe 100644
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -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] == '?':
diff --git a/Lib/tarfile.py b/Lib/tarfile.py
index c3777ff2dd..2d702dd2ec 100755
--- a/Lib/tarfile.py
+++ b/Lib/tarfile.py
@@ -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):
+
+ @path.setter
+ def path(self, name):
self.name = name
- path = property(_getpath, _setpath)
- def _getlinkpath(self):
+ @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))
diff --git a/Lib/test/test_pyclbr.py b/Lib/test/test_pyclbr.py
index 2cff1c526e..9c216d3eb7 100644
--- a/Lib/test/test_pyclbr.py
+++ b/Lib/test/test_pyclbr.py
@@ -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')
diff --git a/Lib/tkinter/ttk.py b/Lib/tkinter/ttk.py
index c474e60713..cbaad76e00 100644
--- a/Lib/tkinter/ttk.py
+++ b/Lib/tkinter/ttk.py
@@ -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."""