From: Angus Lees Date: Wed, 22 Oct 2014 10:20:23 +0000 (+1100) Subject: Enable pylint checks for "anomalous" string escapes X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=e9cee51e56504800ebc51226deb059cf574e3d13;p=openstack-build%2Fneutron-build.git Enable pylint checks for "anomalous" string escapes 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 --- diff --git a/.pylintrc b/.pylintrc index d343d72a6..595c3e53e 100644 --- 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, diff --git a/neutron/agent/linux/ip_link_support.py b/neutron/agent/linux/ip_link_support.py index 146cd06ee..77bd0afed 100644 --- a/neutron/agent/linux/ip_link_support.py +++ b/neutron/agent/linux/ip_link_support.py @@ -45,10 +45,10 @@ class IpLinkConstants(object): class IpLinkSupport(object): - VF_BLOCK_REGEX = "\[ vf NUM(?P.*) \] \]" + VF_BLOCK_REGEX = r"\[ vf NUM(?P.*) \] \]" - 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): diff --git a/neutron/api/v2/attributes.py b/neutron/api/v2/attributes.py index b9ac5730d..7540509d8 100644 --- a/neutron/api/v2/attributes.py +++ b/neutron/api/v2/attributes.py @@ -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) diff --git a/neutron/extensions/loadbalancer.py b/neutron/extensions/loadbalancer.py index fdc23d826..40ef4d9be 100644 --- a/neutron/extensions/loadbalancer.py +++ b/neutron/extensions/loadbalancer.py @@ -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, diff --git a/neutron/extensions/loadbalancerv2.py b/neutron/extensions/loadbalancerv2.py index 6b2f8eee5..8ecb5b683 100644 --- a/neutron/extensions/loadbalancerv2.py +++ b/neutron/extensions/loadbalancerv2.py @@ -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 diff --git a/neutron/plugins/bigswitch/db/consistency_db.py b/neutron/plugins/bigswitch/db/consistency_db.py index f9dd8d1ea..622ee3f5b 100644 --- a/neutron/plugins/bigswitch/db/consistency_db.py +++ b/neutron/plugins/bigswitch/db/consistency_db.py @@ -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] diff --git a/neutron/plugins/midonet/midonet_lib.py b/neutron/plugins/midonet/midonet_lib.py index 863a858d1..b4d206a33 100644 --- a/neutron/plugins/midonet/midonet_lib.py +++ b/neutron/plugins/midonet/midonet_lib.py @@ -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: " diff --git a/neutron/plugins/ml2/drivers/cisco/apic/apic_topology.py b/neutron/plugins/ml2/drivers/cisco/apic/apic_topology.py index b747bb9a5..29b03eae9 100644 --- a/neutron/plugins/ml2/drivers/cisco/apic/apic_topology.py +++ b/neutron/plugins/ml2/drivers/cisco/apic/apic_topology.py @@ -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' diff --git a/neutron/plugins/sriovnicagent/eswitch_manager.py b/neutron/plugins/sriovnicagent/eswitch_manager.py index bd1841fff..0f8e10808 100644 --- a/neutron/plugins/sriovnicagent/eswitch_manager.py +++ b/neutron/plugins/sriovnicagent/eswitch_manager.py @@ -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\d+)" + VIRTFN_FORMAT = r"^virtfn(?P\d+)" VIRTFN_REG_EX = re.compile(VIRTFN_FORMAT) MAC_VTAP_PREFIX = "upper_macvtap*" diff --git a/neutron/policy.py b/neutron/policy.py index f68dabfb0..11e4bf45b 100644 --- a/neutron/policy.py +++ b/neutron/policy.py @@ -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."