Patchwork cleanup: use modern @property/@foo.setter property specification

login
register
mail settings
Submitter Augie Fackler
Date Jan. 16, 2016, 4:46 p.m.
Message ID <c4a5e01f59e037a1fc7f.1452962768@imladris.local>
Download mbox | patch
Permalink /patch/12803/
State Accepted
Commit 52a4ad62b006e8ee2c8ffa95e7162da18824875b
Delegated to: Pierre-Yves David
Headers show

Comments

Augie Fackler - Jan. 16, 2016, 4:46 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1452959428 18000
#      Sat Jan 16 10:50:28 2016 -0500
# Node ID c4a5e01f59e037a1fc7f23fe526760df159e6804
# Parent  0029c2bebc23182c34f83fa22abde1d5d4aebc51
cleanup: use modern @property/@foo.setter property specification

We can use this now that we're 2.6+, and this is more idiomatic modern
Python.
Yuya Nishihara - Jan. 17, 2016, 3:33 p.m.
On Sat, 16 Jan 2016 11:46:08 -0500, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <augie@google.com>
> # Date 1452959428 18000
> #      Sat Jan 16 10:50:28 2016 -0500
> # Node ID c4a5e01f59e037a1fc7f23fe526760df159e6804
> # Parent  0029c2bebc23182c34f83fa22abde1d5d4aebc51
> cleanup: use modern @property/@foo.setter property specification
> 
> We can use this now that we're 2.6+, and this is more idiomatic modern
> Python.

Looks good to me.
Pierre-Yves David - Jan. 18, 2016, 1:17 a.m.
On 01/17/2016 07:33 AM, Yuya Nishihara wrote:
> On Sat, 16 Jan 2016 11:46:08 -0500, Augie Fackler wrote:
>> # HG changeset patch
>> # User Augie Fackler <augie@google.com>
>> # Date 1452959428 18000
>> #      Sat Jan 16 10:50:28 2016 -0500
>> # Node ID c4a5e01f59e037a1fc7f23fe526760df159e6804
>> # Parent  0029c2bebc23182c34f83fa22abde1d5d4aebc51
>> cleanup: use modern @property/@foo.setter property specification
>>
>> We can use this now that we're 2.6+, and this is more idiomatic modern
>> Python.
>
> Looks good to me.

Pushed to the clowncopter.

Patch

diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
--- a/mercurial/bundle2.py
+++ b/mercurial/bundle2.py
@@ -851,13 +851,15 @@  class bundlepart(object):
                               self._advisoryparams, self._data, self.mandatory)
 
     # methods used to defines the part content
-    def __setdata(self, data):
+    @property
+    def data(self):
+        return self._data
+
+    @data.setter
+    def data(self, data):
         if self._generated is not None:
             raise error.ReadOnlyPartError('part is being generated')
         self._data = data
-    def __getdata(self):
-        return self._data
-    data = property(__getdata, __setdata)
 
     @property
     def mandatoryparams(self):
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -448,22 +448,22 @@  class vfs(abstractvfs):
         if realpath:
             base = os.path.realpath(base)
         self.base = base
-        self._setmustaudit(audit)
+        self.mustaudit = audit
         self.createmode = None
         self._trustnlink = None
 
-    def _getmustaudit(self):
+    @property
+    def mustaudit(self):
         return self._audit
 
-    def _setmustaudit(self, onoff):
+    @mustaudit.setter
+    def mustaudit(self, onoff):
         self._audit = onoff
         if onoff:
             self.audit = pathutil.pathauditor(self.base)
         else:
             self.audit = util.always
 
-    mustaudit = property(_getmustaudit, _setmustaudit)
-
     @util.propertycache
     def _cansymlink(self):
         return util.checklink(self.base)
@@ -561,14 +561,14 @@  class auditvfs(object):
     def __init__(self, vfs):
         self.vfs = vfs
 
-    def _getmustaudit(self):
+    @property
+    def mustaudit(self):
         return self.vfs.mustaudit
 
-    def _setmustaudit(self, onoff):
+    @mustaudit.setter
+    def mustaudit(self, onoff):
         self.vfs.mustaudit = onoff
 
-    mustaudit = property(_getmustaudit, _setmustaudit)
-
 class filtervfs(abstractvfs, auditvfs):
     '''Wrapper vfs for filtering filenames with a function.'''