Browse Source

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
changes/84/130184/5
Angus Lees 7 years ago
parent
commit
e9cee51e56
  1. 3
      .pylintrc
  2. 6
      neutron/agent/linux/ip_link_support.py
  3. 2
      neutron/api/v2/attributes.py
  4. 2
      neutron/extensions/loadbalancer.py
  5. 2
      neutron/extensions/loadbalancerv2.py
  6. 2
      neutron/plugins/bigswitch/db/consistency_db.py
  7. 14
      neutron/plugins/midonet/midonet_lib.py
  8. 4
      neutron/plugins/ml2/drivers/cisco/apic/apic_topology.py
  9. 2
      neutron/plugins/sriovnicagent/eswitch_manager.py
  10. 2
      neutron/policy.py

3
.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,

6
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>.*) \] \]"
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):

2
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)

2
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,

2
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

2
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]

14
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: "

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

2
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<vf_index>\d+)"
VIRTFN_FORMAT = r"^virtfn(?P<vf_index>\d+)"
VIRTFN_REG_EX = re.compile(VIRTFN_FORMAT)
MAC_VTAP_PREFIX = "upper_macvtap*"

2
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."

Loading…
Cancel
Save