Bug 1344836 - Enable flake8 rule E713: "test for membership should be 'not in'". r?dexter draft
authorFederico Padua <federico_padua@yahoo.it>
Tue, 14 Mar 2017 02:03:13 +0100
changeset 500991 647787403b689f915270aaa63bf1192ea8ad832b
parent 500857 23a4b7430dd7e83a2809bf3dc41471f154301eda
child 549775 1209587c7cec6d9eca04399427910d2cc2bbcb5b
push id49869
push userbmo:federico_padua@yahoo.it
push dateSat, 18 Mar 2017 10:53:05 +0000
reviewersdexter
bugs1344836
milestone55.0a1
Bug 1344836 - Enable flake8 rule E713: "test for membership should be 'not in'". r?dexter This patch enables flake8 rule E713: "test for membership should be 'not in'" in toolkit/components/telemetry by removing the relative E713 entry from toolkit/components/telemetry/.flake8 and fixing the files for which the E713 error was reported. Precisely 6 errors violating E713 rule were found and solved. MozReview-Commit-ID: 2AaYGgVkxbU
toolkit/components/telemetry/.flake8
toolkit/components/telemetry/gen-event-enum.py
toolkit/components/telemetry/histogram_tools.py
toolkit/components/telemetry/parse_events.py
--- 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, E128, E501, E713, E202, W602, E127, W601
+ignore = E121, E123, E126, E129, E133, E226, E241, E242, E704, W503, E402, E128, E501, E202, W602, E127, W601
 max-line-length = 99
 filename = *.py, +.lint
--- a/toolkit/components/telemetry/gen-event-enum.py
+++ b/toolkit/components/telemetry/gen-event-enum.py
@@ -35,17 +35,17 @@ def main(output, *filenames):
     if len(filenames) > 1:
         raise Exception('We don\'t support loading from more than one file.')
     events = parse_events.load_events(filenames[0])
 
     grouped = dict()
     index = 0
     for e in events:
         category = e.category
-        if not category in grouped:
+        if category not in grouped:
             grouped[category] = []
         grouped[category].append((index, e))
         index += len(e.enum_labels)
 
     # Write the enum file.
     print(banner, file=output)
     print(file_header, file=output)
 
--- a/toolkit/components/telemetry/histogram_tools.py
+++ b/toolkit/components/telemetry/histogram_tools.py
@@ -129,17 +129,17 @@ symbol that should guard C/C++ definitio
             'linear': 'LINEAR',
             'exponential': 'EXPONENTIAL',
         }
         table_dispatch(self.kind(), table,
                        lambda k: self._set_nsITelemetry_kind(k))
         datasets = {'opt-in': 'DATASET_RELEASE_CHANNEL_OPTIN',
                     'opt-out': 'DATASET_RELEASE_CHANNEL_OPTOUT'}
         value = definition.get('releaseChannelCollection', 'opt-in')
-        if not value in datasets:
+        if value not in datasets:
             raise DefinitionException, "unknown release channel collection policy for " + name
         self._dataset = "nsITelemetry::" + datasets[value]
 
     def name(self):
         """Return the name of the histogram."""
         return self._name
 
     def description(self):
@@ -362,24 +362,24 @@ associated with the histogram.  Returns 
                 definition["keyed"] = True
 
         def nice_type_name(t):
             if t is basestring:
                 return "string"
             return t.__name__
 
         for key, key_type in type_checked_fields.iteritems():
-            if not key in definition:
+            if key not in definition:
                 continue
             if not isinstance(definition[key], key_type):
                 raise ValueError, ('value for key "{0}" in Histogram "{1}" '
                         'should be {2}').format(key, name, nice_type_name(key_type))
 
         for key, key_type in type_checked_list_fields.iteritems():
-            if not key in definition:
+            if key not in definition:
                 continue
             if not all(isinstance(x, key_type) for x in definition[key]):
                 raise ValueError, ('all values for list "{0}" in Histogram "{1}" '
                         'should be {2}').format(key, name, nice_type_name(key_type))
 
     @staticmethod
     def check_keys(name, definition, allowed_keys):
         for key in definition.iterkeys():
--- a/toolkit/components/telemetry/parse_events.py
+++ b/toolkit/components/telemetry/parse_events.py
@@ -164,17 +164,17 @@ class EventData:
             string_check(self.identifier, field='objects', value=obj,
                          min_length=1, max_length=MAX_OBJECT_NAME_LENGTH,
                          regex=IDENTIFIER_PATTERN)
 
         # Check release_channel_collection
         rcc_key = 'release_channel_collection'
         rcc = definition.get(rcc_key, 'opt-in')
         allowed_rcc = ["opt-in", "opt-out"]
-        if not rcc in allowed_rcc:
+        if rcc not in allowed_rcc:
             raise ValueError, "%s: value for %s should be one of: %s" %\
                               (self.identifier, rcc_key, ", ".join(allowed_rcc))
 
         # Check record_in_processes.
         record_in_processes = definition.get('record_in_processes')
         for proc in record_in_processes:
             if not utils.is_valid_process_name(proc):
                 raise ValueError(self.identifier + ': unknown value in record_in_processes: ' + proc)
@@ -185,17 +185,17 @@ class EventData:
             raise ValueError, "%s: number of extra_keys exceeds limit %d" %\
                               (self.identifier, MAX_EXTRA_KEYS_COUNT)
         for key in extra_keys.iterkeys():
             string_check(self.identifier, field='extra_keys', value=key,
                          min_length=1, max_length=MAX_EXTRA_KEY_NAME_LENGTH,
                          regex=IDENTIFIER_PATTERN)
 
         # Check expiry.
-        if not 'expiry_version' in definition and not 'expiry_date' in definition:
+        if 'expiry_version' not in definition and 'expiry_date' not in definition:
             raise KeyError, "%s: event is missing an expiration - either expiry_version or expiry_date is required" %\
                             (self.identifier)
         expiry_date = definition.get('expiry_date')
         if expiry_date and isinstance(expiry_date, basestring) and expiry_date != 'never':
             if not re.match(DATE_PATTERN, expiry_date):
                 raise ValueError, "%s: event has invalid expiry_date, it should be either 'never' or match this format: %s" %\
                                   (self.identifier, DATE_PATTERN)
             # Parse into date.