Bug 1344832 - Enable flake8 rule E502: "the backslash is redundant between brackets". r+dexter
This patch enables flake8 rule E502:
"the backslash is redundant between brackets" in toolkit/components/telemetry
by removing the relative E502 entry from toolkit/components/telemetry/.flake8
and fixing the files for which the E502 error was reported.
Precisely 8 errors violating E502 rule were found and solved.
MozReview-Commit-ID: 1z8f3JjJ2gt
--- a/toolkit/components/telemetry/.flake8
+++ b/toolkit/components/telemetry/.flake8
@@ -1,5 +1,5 @@
[flake8]
# See http://pep8.readthedocs.io/en/latest/intro.html#configuration
-ignore = E121, E123, E126, E129, E133, E226, E241, E242, E704, W503, E402, E502, E128, E501, E713, E222, E201, E202, W602, E127, W601
+ignore = E121, E123, E126, E129, E133, E226, E241, E242, E704, W503, E402, E128, E501, E713, E222, E201, E202, W602, E127, W601
max-line-length = 99
filename = *.py, +.lint
--- a/toolkit/components/telemetry/gen-histogram-data.py
+++ b/toolkit/components/telemetry/gen-histogram-data.py
@@ -15,17 +15,17 @@ import itertools
banner = """/* This file is auto-generated, see gen-histogram-data.py. */
"""
def print_array_entry(output, histogram, name_index, exp_index, label_index, label_count):
cpp_guard = histogram.cpp_guard()
if cpp_guard:
print("#if defined(%s)" % cpp_guard, file=output)
- print(" { %s, %s, %s, %s, %d, %d, %s, %d, %d, %s }," \
+ print(" { %s, %s, %s, %s, %d, %d, %s, %d, %d, %s },"
% (histogram.low(),
histogram.high(),
histogram.n_buckets(),
histogram.nsITelemetry_kind(),
name_index,
exp_index,
histogram.dataset(),
label_index,
--- a/toolkit/components/telemetry/gen-scalar-data.py
+++ b/toolkit/components/telemetry/gen-scalar-data.py
@@ -36,17 +36,17 @@ def write_scalar_info(scalar, output, na
:param output: the output stream.
:param name_index: the index of the scalar name in the strings table.
:param expiration_index: the index of the expiration version in the strings table.
"""
cpp_guard = scalar.cpp_guard
if cpp_guard:
print("#if defined(%s)" % cpp_guard, file=output)
- print(" {{ {}, {}, {}, {}, {}, {} }},"\
+ print(" {{ {}, {}, {}, {}, {}, {} }},"
.format(scalar.nsITelemetry_kind,
name_index,
expiration_index,
scalar.dataset,
" | ".join(scalar.record_in_processes_enum),
"true" if scalar.keyed else "false"),
file=output)
--- a/toolkit/components/telemetry/parse_events.py
+++ b/toolkit/components/telemetry/parse_events.py
@@ -129,20 +129,20 @@ def type_check_event_fields(identifier,
# Type-check fields.
for k, v in definition.iteritems():
ALL_FIELDS[k].check(identifier, k, v)
def string_check(identifier, field, value, min_length=1, max_length=None, regex=None):
# Length check.
if len(value) < min_length:
- raise ValueError("%s: value '%s' for field %s is less than minimum length of %d" %\
+ raise ValueError("%s: value '%s' for field %s is less than minimum length of %d" %
(identifier, value, field, min_length))
if max_length and len(value) > max_length:
- raise ValueError("%s: value '%s' for field %s is greater than maximum length of %d" %\
+ raise ValueError("%s: value '%s' for field %s is greater than maximum length of %d" %
(identifier, value, field, max_length))
# Regex check.
if regex and not re.match(regex, value):
raise ValueError, '%s: string value "%s" for %s is not matching pattern "%s"' % \
(identifier, value, field, regex)
class EventData:
--- a/toolkit/components/telemetry/parse_scalars.py
+++ b/toolkit/components/telemetry/parse_scalars.py
@@ -43,29 +43,29 @@ class ScalarType:
:raises ValueError: if the length of the names exceeds the limit or they don't
conform our name specification.
"""
# Enforce a maximum length on group and probe names.
MAX_NAME_LENGTH = 40
for n in [group_name, probe_name]:
if len(n) > MAX_NAME_LENGTH:
- raise ValueError("Name '{}' exceeds maximum name length of {} characters."\
+ raise ValueError("Name '{}' exceeds maximum name length of {} characters."
.format(n, MAX_NAME_LENGTH))
def check_name(name, error_msg_prefix, allowed_char_regexp):
# Check if we only have the allowed characters.
chars_regxp = r'^[a-zA-Z0-9' + allowed_char_regexp + r']+$'
if not re.search(chars_regxp, name):
raise ValueError(error_msg_prefix + " name must be alpha-numeric. Got: '{}'".format(name))
# Don't allow leading/trailing digits, '.' or '_'.
if re.search(r'(^[\d\._])|([\d\._])$', name):
raise ValueError(error_msg_prefix +
- " name must not have a leading/trailing digit, a dot or underscore. Got: '{}'"\
+ " name must not have a leading/trailing digit, a dot or underscore. Got: '{}'"
.format(name))
check_name(group_name, 'Group', r'\.')
check_name(probe_name, 'Probe', r'_')
def validate_types(self, definition):
"""This function performs some basic sanity checks on the scalar definition:
- Checks that all the required fields are available.
@@ -109,17 +109,17 @@ class ScalarType:
raise KeyError(self._name + ' - missing required fields: ' + ', '.join(missing_fields))
# Do we have any unknown field?
unknown_fields = [f for f in definition.keys() if f not in ALL_FIELDS]
if len(unknown_fields) > 0:
raise KeyError(self._name + ' - unknown fields: ' + ', '.join(unknown_fields))
# Checks the type for all the fields.
- wrong_type_names = ['{} must be {}'.format(f, ALL_FIELDS[f].__name__) \
+ wrong_type_names = ['{} must be {}'.format(f, ALL_FIELDS[f].__name__)
for f in definition.keys() if not isinstance(definition[f], ALL_FIELDS[f])]
if len(wrong_type_names) > 0:
raise TypeError(self._name + ' - ' + ', '.join(wrong_type_names))
# Check that the lists are not empty and that data in the lists
# have the correct types.
list_fields = [f for f in definition if isinstance(definition[f], list)]
for field in list_fields:
@@ -231,17 +231,17 @@ class ScalarType:
def dataset(self):
"""Get the nsITelemetry constant equivalent to the chose release channel collection
policy for the scalar.
"""
# The collection policy is optional, but we still define a default
# behaviour for it.
release_channel_collection = \
self._definition.get('release_channel_collection', 'opt-in')
- return 'nsITelemetry::' + ('DATASET_RELEASE_CHANNEL_OPTOUT' \
+ return 'nsITelemetry::' + ('DATASET_RELEASE_CHANNEL_OPTOUT'
if release_channel_collection == 'opt-out' else 'DATASET_RELEASE_CHANNEL_OPTIN')
@property
def cpp_guard(self):
"""Get the cpp guard for this scalar"""
return self._definition.get('cpp_guard')