[PATCH] cleanup: use modern @property/@foo.setter property specification

Augie Fackler raf at durin42.com
Sat Jan 16 16:46:08 UTC 2016


# HG changeset patch
# User Augie Fackler <augie at 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.

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.'''
 


More information about the Mercurial-devel mailing list