]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Enable pylint checks for "anomalous" string escapes
authorAngus Lees <gus@inodes.org>
Wed, 22 Oct 2014 10:20:23 +0000 (21:20 +1100)
committerAngus Lees <gus@inodes.org>
Tue, 23 Dec 2014 03:53:02 +0000 (14:53 +1100)
Escapes in python string literals are well defined, but can be
confusing.  These pylint checks look for backslash escapes in strings
that might be mistakes.  Two code refactors were required to satisfy
these tests:

1. midonet_lib.py used \**kwargs in docstrings.

There doesn't seem to be a sphinx standard for kwargs, so this change
simply replaces them with "kwargs".

2. Regex literals containing escapes replaced with r''.

The assumption with this change (and the underlying pylint
check) is that r'' literals are more straightforward for regular
expressions, where every backslash is important.

While looking at these regexes, this change also removes a few
unnecessary "\-" escapes.

Change-Id: I01528b2482f78b9e851685ebbf6fded4e58355f1

.pylintrc
neutron/agent/linux/ip_link_support.py
neutron/api/v2/attributes.py
neutron/extensions/loadbalancer.py
neutron/extensions/loadbalancerv2.py
neutron/plugins/bigswitch/db/consistency_db.py
neutron/plugins/midonet/midonet_lib.py
neutron/plugins/ml2/drivers/cisco/apic/apic_topology.py
neutron/plugins/sriovnicagent/eswitch_manager.py
neutron/policy.py

index d343d72a641b0bb55cdcbb87baa58568b61407a6..595c3e53e684b29d46b27d491c1da42fcbb3036c 100644 (file)
--- a/.pylintrc
+++ b/.pylintrc
@@ -27,11 +27,8 @@ disable=
  not-callable,
  no-value-for-parameter,
  super-on-old-class,
- too-few-format-args,
 # "W" Warnings for stylistic problems or minor programming issues
  abstract-method,
- anomalous-backslash-in-string,
- anomalous-unicode-escape-in-string,
  arguments-differ,
  attribute-defined-outside-init,
  bad-builtin,
index 146cd06ee23853cc0516ca96d3bc366e17b6470e..77bd0afedfe1702e29f4a8c65f4f581e01dac75f 100644 (file)
@@ -45,10 +45,10 @@ class IpLinkConstants(object):
 
 
 class IpLinkSupport(object):
-    VF_BLOCK_REGEX = "\[ vf NUM(?P<vf_block>.*) \] \]"
+    VF_BLOCK_REGEX = r"\[ vf NUM(?P<vf_block>.*) \] \]"
 
-    CAPABILITY_REGEX = "\[ %s (.*)"
-    SUB_CAPABILITY_REGEX = "\[ %(cap)s (.*) \[ %(subcap)s (.*)"
+    CAPABILITY_REGEX = r"\[ %s (.*)"
+    SUB_CAPABILITY_REGEX = r"\[ %(cap)s (.*) \[ %(subcap)s (.*)"
 
     @classmethod
     def get_vf_mgmt_section(cls, root_helper=None):
index b9ac5730d95756621f27de6f3c2837f096ae52d7..7540509d8bfb92580f267ba17b58d8096006f02c 100644 (file)
@@ -143,7 +143,7 @@ def _validate_range(data, valid_values=None):
 
 def _validate_no_whitespace(data):
     """Validates that input has no whitespace."""
-    if re.search('\s', data):
+    if re.search(r'\s', data):
         msg = _("'%s' contains whitespace") % data
         LOG.debug(msg)
         raise n_exc.InvalidInput(error_message=msg)
index fdc23d8265e9b8dbb300f2eb07e82017a397fa8e..40ef4d9be508d3f3094bc109e470aa4b666dd664 100644 (file)
@@ -274,7 +274,7 @@ RESOURCE_ATTRIBUTE_MAP = {
         'expected_codes': {'allow_post': True, 'allow_put': True,
                            'validate': {
                                'type:regex':
-                               '^(\d{3}(\s*,\s*\d{3})*)$|^(\d{3}-\d{3})$'},
+                               r'^(\d{3}(\s*,\s*\d{3})*)$|^(\d{3}-\d{3})$'},
                            'default': '200',
                            'is_visible': True},
         'admin_state_up': {'allow_post': True, 'allow_put': True,
index 6b2f8eee50dafe9ff83debd8a8ebae07dce40107..8ecb5b6833a316e933804839f3bad5401b304779 100644 (file)
@@ -280,7 +280,7 @@ RESOURCE_ATTRIBUTE_MAP = {
             'allow_post': True,
             'allow_put': True,
             'validate': {
-                'type:regex': '^(\d{3}(\s*,\s*\d{3})*)$|^(\d{3}-\d{3})$'
+                'type:regex': r'^(\d{3}(\s*,\s*\d{3})*)$|^(\d{3}-\d{3})$'
             },
             'default': '200',
             'is_visible': True
index f9dd8d1eacbc18635885bd823b4ce40bb123648b..622ee3f5bf250fdadabf2fceef4a863e384a5f80 100644 (file)
@@ -119,7 +119,7 @@ class HashHandler(object):
         return result.rowcount != 0
 
     def _get_lock_owner(self, record):
-        matches = re.findall("^LOCKED_BY\[(\w+)\]", record)
+        matches = re.findall(r"^LOCKED_BY\[(\w+)\]", record)
         if not matches:
             return None
         return matches[0]
index 863a858d1f1a575d3b94cdb2a8f510dafe9d5df9..b4d206a33ff3f2cd526ce5c44363a6787d7e9980 100644 (file)
@@ -72,7 +72,7 @@ class MidoClient:
     def create_bridge(self, **kwargs):
         """Create a new bridge
 
-        :param \**kwargs: configuration of the new bridge
+        :param kwargs: configuration of the new bridge
         :returns: newly created bridge
         """
         LOG.debug("MidoClient.create_bridge called: "
@@ -106,7 +106,7 @@ class MidoClient:
         """Update a bridge of the given id with the new fields
 
         :param id: id of the bridge
-        :param \**kwargs: the fields to update and their values
+        :param kwargs: the fields to update and their values
         :returns: bridge object
         """
         LOG.debug("MidoClient.update_bridge called: "
@@ -250,7 +250,7 @@ class MidoClient:
         """Add a port on a bridge
 
         :param bridge: bridge to add a new port to
-        :param \**kwargs: configuration of the new port
+        :param kwargs: configuration of the new port
         :returns: newly created port
         """
         LOG.debug("MidoClient.add_bridge_port called: "
@@ -263,7 +263,7 @@ class MidoClient:
         """Update a port of the given id with the new fields
 
         :param id: id of the port
-        :param \**kwargs: the fields to update and their values
+        :param kwargs: the fields to update and their values
         """
         LOG.debug("MidoClient.update_port called: "
                   "id=%(id)s, kwargs=%(kwargs)s",
@@ -278,7 +278,7 @@ class MidoClient:
         """Add a new port to an existing router.
 
         :param router: router to add a new port to
-        :param \**kwargs: configuration of the new port
+        :param kwargs: configuration of the new port
         :returns: newly created port
         """
         return self._create_dto(self.mido_api.add_router_port(router), kwargs)
@@ -287,7 +287,7 @@ class MidoClient:
     def create_router(self, **kwargs):
         """Create a new router
 
-        :param \**kwargs: configuration of the new router
+        :param kwargs: configuration of the new router
         :returns: newly created router
         """
         LOG.debug("MidoClient.create_router called: "
@@ -321,7 +321,7 @@ class MidoClient:
         """Update a router of the given id with the new name
 
         :param id: id of the router
-        :param \**kwargs: the fields to update and their values
+        :param kwargs: the fields to update and their values
         :returns: router object
         """
         LOG.debug("MidoClient.update_router called: "
index b747bb9a5422d40947033fdb91388e08ddc7a442..29b03eae9a3e759d893f408511b6d4774b012e84 100644 (file)
@@ -42,8 +42,8 @@ from neutron.plugins.ml2.drivers import type_vlan  # noqa
 from neutron import service
 
 ACI_PORT_DESCR_FORMATS = [
-    'topology/pod-1/node-(\d+)/sys/conng/path-\[eth(\d+)/(\d+)\]',
-    'topology/pod-1/paths-(\d+)/pathep-\[eth(\d+)/(\d+)\]',
+    r'topology/pod-1/node-(\d+)/sys/conng/path-\[eth(\d+)/(\d+)\]',
+    r'topology/pod-1/paths-(\d+)/pathep-\[eth(\d+)/(\d+)\]',
 ]
 AGENT_FORCE_UPDATE_COUNT = 100
 BINARY_APIC_SERVICE_AGENT = 'neutron-cisco-apic-service-agent'
index bd1841fffd90ae770dd8621c92369839699669a7..0f8e1080846a7a70b6bb5b0da7b2526aebe83735 100644 (file)
@@ -30,7 +30,7 @@ class PciOsWrapper(object):
 
     DEVICE_PATH = "/sys/class/net/%s/device"
     PCI_PATH = "/sys/class/net/%s/device/virtfn%s/net"
-    VIRTFN_FORMAT = "^virtfn(?P<vf_index>\d+)"
+    VIRTFN_FORMAT = r"^virtfn(?P<vf_index>\d+)"
     VIRTFN_REG_EX = re.compile(VIRTFN_FORMAT)
     MAC_VTAP_PREFIX = "upper_macvtap*"
 
index f68dabfb00758d2512ad8d40d95baa8e3edcf8bc..11e4bf45b234dd27329d2d819f6a677507c0fd4a 100644 (file)
@@ -246,7 +246,7 @@ class OwnerCheck(policy.Check):
     def __init__(self, kind, match):
         # Process the match
         try:
-            self.target_field = re.findall('^\%\((.*)\)s$',
+            self.target_field = re.findall(r'^\%\((.*)\)s$',
                                            match)[0]
         except IndexError:
             err_reason = (_("Unable to identify a target field from:%s."