[blivet:master 13/13] Rename to avoid redefining parameter built-ins

Martin Kolman mkolman at redhat.com
Fri Apr 25 13:47:52 UTC 2014


On Fri, 2014-04-25 at 08:54 -0400, mulhern wrote:
> When renaming a parameter it is necessary to check whether the parameter is
> used as a keyword in function invocations. In all these cases, that does
> not occur, i.e, in blivet, anaconda, open-lmi these functions, if they are
> invoked, are only invoked using positional arguments.
Just in case I've tried to search for some of the more unique function
calls in Github code search but I've also haven't found any other users
of the old keyword arguments, just a couple of more or less outdated
Anaconda & Blivet forks. So it should indeed be safe to change.


> ---
>  blivet/__init__.py |  6 +++---
>  blivet/devices.py  | 18 +++++++++---------
>  blivet/zfcp.py     | 36 ++++++++++++++++++------------------
>  tests/size_test.py | 22 +++++++++++-----------
>  4 files changed, 41 insertions(+), 41 deletions(-)
> 
> diff --git a/blivet/__init__.py b/blivet/__init__.py
> index c9a980a..fda44e8 100644
> --- a/blivet/__init__.py
> +++ b/blivet/__init__.py
> @@ -1254,12 +1254,12 @@ class Blivet(object):
>          action = ActionDestroyDevice(device)
>          self.devicetree.registerAction(action)
>  
> -    def formatDevice(self, device, format):
> +    def formatDevice(self, device, fmt):
>          """ Schedule formatting of a device.
>  
>              :param device: the device to create the formatting on
>              :type device: :class:`~.devices.StorageDevice`
> -            :param format: the format to create on the device
> +            :param fmt: the format to create on the device
>              :type format: :class:`~.formats.DeviceFormat`
>              :rtype: None
>  
> @@ -1269,7 +1269,7 @@ class Blivet(object):
>              method.
>          """
>          self.devicetree.registerAction(ActionDestroyFormat(device))
> -        self.devicetree.registerAction(ActionCreateFormat(device, format))
> +        self.devicetree.registerAction(ActionCreateFormat(device, fmt))
>  
>      def resetDevice(self, device):
>          """ Cancel all scheduled actions and reset formatting.
> diff --git a/blivet/devices.py b/blivet/devices.py
> index 1219801..1135b49 100644
> --- a/blivet/devices.py
> +++ b/blivet/devices.py
> @@ -985,17 +985,17 @@ class StorageDevice(Device):
>              return False
>          return os.access(self.path, os.W_OK)
>  
> -    def _setFormat(self, format):
> +    def _setFormat(self, fmt):
>          """ Set the Device's format. """
> -        if not format:
> -            format = getFormat(None, device=self.path, exists=self.exists)
> -        log_method_call(self, self.name, type=format.type,
> +        if not fmt:
> +            fmt = getFormat(None, device=self.path, exists=self.exists)
> +        log_method_call(self, self.name, type=fmt.type,
>                          current=getattr(self._format, "type", None))
>          if self._format and self._format.status:
>              # FIXME: self.format.status doesn't mean much
>              raise errors.DeviceError("cannot replace active format", self.name)
>  
> -        self._format = format
> +        self._format = fmt
>          self._format.device = self.path
>  
>      def _getFormat(self):
> @@ -1510,10 +1510,10 @@ class PartitionDevice(StorageDevice):
>                                   self.disk.format.logicalPartitions))
>          return (no_kids and not extended_has_logical)
>  
> -    def _setFormat(self, format):
> +    def _setFormat(self, fmt):
>          """ Set the Device's format. """
>          log_method_call(self, self.name)
> -        StorageDevice._setFormat(self, format)
> +        StorageDevice._setFormat(self, fmt)
>  
>      def _setBootable(self, bootable):
>          """ Set the bootable flag for this partition. """
> @@ -4627,9 +4627,9 @@ class BTRFSVolumeDevice(BTRFSDevice, ContainerDevice):
>  
>          self._defaultSubVolumeID = None
>  
> -    def _setFormat(self, format):
> +    def _setFormat(self, fmt):
>          """ Set the Device's format. """
> -        super(BTRFSVolumeDevice, self)._setFormat(format)
> +        super(BTRFSVolumeDevice, self)._setFormat(fmt)
>          self._name = "btrfs.%d" % self.id
>          label = getattr(self.format, "label", None)
>          if label:
> diff --git a/blivet/zfcp.py b/blivet/zfcp.py
> index 2dc5aff..6405820 100644
> --- a/blivet/zfcp.py
> +++ b/blivet/zfcp.py
> @@ -66,13 +66,13 @@ class ZFCPDevice:
>          else:
>              return bus + dev
>  
> -    def sanitizeWWPNInput(self, id):
> -        if id is None or id == "":
> +    def sanitizeWWPNInput(self, wwpn):
> +        if wwpn is None or wwpn == "":
>              return None
> -        id = id.lower()
> -        if id[:2] != "0x":
> -            return "0x" + id
> -        return id
> +        wwpn = wwpn.lower()
> +        if wwpn[:2] != "0x":
> +            return "0x" + wwpn
> +        return wwpn
>  
>      # ZFCP LUNs are usually entered as 16 bit, sysfs accepts only 64 bit 
>      # (#125632), expand with zeroes if necessary
> @@ -86,30 +86,30 @@ class ZFCPDevice:
>          lun = lun + "0" * (16 - len(lun) + 2)
>          return lun
>  
> -    def _hextest(self, hex):
> +    def _hextest(self, hexnum):
>          try:
> -            int(hex, 16)
> +            int(hexnum, 16)
>              return True
>          except TypeError:
>              return False
>  
> -    def checkValidDevice(self, id):
> -        if id is None or id == "":
> +    def checkValidDevice(self, devnum):
> +        if devnum is None or devnum == "":
>              return False
> -        if len(id) != 8:             # p.e. 0.0.0600
> +        if len(devnum) != 8:             # p.e. 0.0.0600
>              return False
> -        if id[0] not in string.digits or id[2] not in string.digits:
> +        if devnum[0] not in string.digits or devnum[2] not in string.digits:
>              return False
> -        if id[1] != "." or id[3] != ".":
> +        if devnum[1] != "." or devnum[3] != ".":
>              return False
> -        return self._hextest(id[4:])
> +        return self._hextest(devnum[4:])
>  
> -    def checkValid64BitHex(self, hex):
> -        if hex is None or hex == "":
> +    def checkValid64BitHex(self, hexnum):
> +        if hexnum is None or hexnum == "":
>              return False
> -        if len(hex) != 18:
> +        if len(hexnum) != 18:
>              return False
> -        return self._hextest(hex)
> +        return self._hextest(hexnum)
>      checkValidWWPN = checkValidFCPLun = checkValid64BitHex
>  
>      def onlineDevice(self):
> diff --git a/tests/size_test.py b/tests/size_test.py
> index 53bac3f..7029fdc 100644
> --- a/tests/size_test.py
> +++ b/tests/size_test.py
> @@ -39,35 +39,35 @@ class SizeTestCase(unittest.TestCase):
>  
>          self.assertEqual(s.humanReadable(places=0), "500 B")
>  
> -    def _prefixTestHelper(self, bytes, factor, prefix, abbr):
> -        c = bytes * factor
> +    def _prefixTestHelper(self, numbytes, factor, prefix, abbr):
> +        c = numbytes * factor
>  
>          s = Size(bytes=c)
>          self.assertEquals(s, c)
>  
>          if prefix:
>              u = "%sbytes" % prefix
> -            s = Size(spec="%ld %s" % (bytes, u))
> +            s = Size(spec="%ld %s" % (numbytes, u))
>              self.assertEquals(s, c)
> -            self.assertEquals(s.convertTo(spec=u), bytes)
> +            self.assertEquals(s.convertTo(spec=u), numbytes)
>  
>          if abbr:
>              u = "%sb" % abbr
> -            s = Size(spec="%ld %s" % (bytes, u))
> +            s = Size(spec="%ld %s" % (numbytes, u))
>              self.assertEquals(s, c)
> -            self.assertEquals(s.convertTo(spec=u), bytes)
> +            self.assertEquals(s.convertTo(spec=u), numbytes)
>  
>          if not prefix and not abbr:
> -            s = Size(spec="%ld" % bytes)
> +            s = Size(spec="%ld" % numbytes)
>              self.assertEquals(s, c)
> -            self.assertEquals(s.convertTo(), bytes)
> +            self.assertEquals(s.convertTo(), numbytes)
>  
>      def testPrefixes(self):
> -        bytes = 47L
> -        self._prefixTestHelper(bytes, 1, None, None)
> +        numbytes = 47L
> +        self._prefixTestHelper(numbytes, 1, None, None)
>  
>          for factor, prefix, abbr in _prefixes:
> -            self._prefixTestHelper(bytes, factor, prefix, abbr)
> +            self._prefixTestHelper(numbytes, factor, prefix, abbr)
>  
>      def testHumanReadable(self):
>          s = Size(bytes=58929971L)




More information about the anaconda-patches mailing list