Skip to content

Commit

Permalink
Fix remaining flake8 warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
saschanaz committed Jun 21, 2020
1 parent c953931 commit d01648d
Show file tree
Hide file tree
Showing 28 changed files with 332 additions and 314 deletions.
1 change: 1 addition & 0 deletions components/net/tests/cookie_http_state_utils.py
Expand Up @@ -170,5 +170,6 @@ def update_test_file(cachedir):

return 0


if __name__ == "__main__":
update_test_file(tempfile.gettempdir())
337 changes: 169 additions & 168 deletions components/script/dom/bindings/codegen/CodegenRust.py

Large diffs are not rendered by default.

77 changes: 44 additions & 33 deletions components/script/dom/bindings/codegen/Configuration.py
Expand Up @@ -63,7 +63,8 @@ def __init__(self, filename, parseData):
c.isCallback() and not c.isInterface()]

# Keep the descriptor list sorted for determinism.
cmp = lambda x, y: (x > y) - (x < y)
def cmp(x, y):
return (x > y) - (x < y)
self.descriptors.sort(key=functools.cmp_to_key(lambda x, y: cmp(x.name, y.name)))

def getInterface(self, ifname):
Expand All @@ -74,25 +75,35 @@ def getDescriptors(self, **filters):
curr = self.descriptors
for key, val in filters.iteritems():
if key == 'webIDLFile':
getter = lambda x: x.interface.filename()
def getter(x):
return x.interface.filename()
elif key == 'hasInterfaceObject':
getter = lambda x: x.interface.hasInterfaceObject()
def getter(x):
return x.interface.hasInterfaceObject()
elif key == 'isCallback':
getter = lambda x: x.interface.isCallback()
def getter(x):
return x.interface.isCallback()
elif key == 'isNamespace':
getter = lambda x: x.interface.isNamespace()
def getter(x):
return x.interface.isNamespace()
elif key == 'isJSImplemented':
getter = lambda x: x.interface.isJSImplemented()
def getter(x):
return x.interface.isJSImplemented()
elif key == 'isGlobal':
getter = lambda x: x.isGlobal()
def getter(x):
return x.isGlobal()
elif key == 'isInline':
getter = lambda x: x.interface.getExtendedAttribute('Inline') is not None
def getter(x):
return x.interface.getExtendedAttribute('Inline') is not None
elif key == 'isExposedConditionally':
getter = lambda x: x.interface.isExposedConditionally()
def getter(x):
return x.interface.isExposedConditionally()
elif key == 'isIteratorInterface':
getter = lambda x: x.interface.isIteratorInterface()
def getter(x):
return x.interface.isIteratorInterface()
else:
getter = lambda x: getattr(x, key)
def getter(x):
return getattr(x, key)
curr = filter(lambda x: getter(x) == val, curr)
return curr

Expand Down Expand Up @@ -125,8 +136,8 @@ def getDescriptor(self, interfaceName):

# We should have exactly one result.
if len(descriptors) != 1:
raise NoSuchDescriptorError("For " + interfaceName + " found " +
str(len(descriptors)) + " matches")
raise NoSuchDescriptorError("For " + interfaceName + " found "
+ str(len(descriptors)) + " matches")
return descriptors[0]

def getDescriptorProvider(self):
Expand Down Expand Up @@ -157,10 +168,10 @@ def getDescriptor(self, interfaceName):


def MemberIsUnforgeable(member, descriptor):
return ((member.isAttr() or member.isMethod()) and
not member.isStatic() and
(member.isUnforgeable() or
bool(descriptor.interface.getExtendedAttribute("Unforgeable"))))
return ((member.isAttr() or member.isMethod())
and not member.isStatic()
and (member.isUnforgeable()
or bool(descriptor.interface.getExtendedAttribute("Unforgeable"))))


class Descriptor(DescriptorProvider):
Expand Down Expand Up @@ -228,14 +239,14 @@ def __init__(self, config, interface, desc):

# If we're concrete, we need to crawl our ancestor interfaces and mark
# them as having a concrete descendant.
self.concrete = (not self.interface.isCallback() and
not self.interface.isNamespace() and
not self.interface.getExtendedAttribute("Abstract") and
not self.interface.getExtendedAttribute("Inline") and
not spiderMonkeyInterface)
self.hasUnforgeableMembers = (self.concrete and
any(MemberIsUnforgeable(m, self) for m in
self.interface.members))
self.concrete = (not self.interface.isCallback()
and not self.interface.isNamespace()
and not self.interface.getExtendedAttribute("Abstract")
and not self.interface.getExtendedAttribute("Inline")
and not spiderMonkeyInterface)
self.hasUnforgeableMembers = (self.concrete
and any(MemberIsUnforgeable(m, self) for m in
self.interface.members))

self.operations = {
'IndexedGetter': None,
Expand Down Expand Up @@ -391,8 +402,8 @@ def getParentName(self):
return None

def hasDescendants(self):
return (self.interface.getUserData("hasConcreteDescendant", False) or
self.interface.getUserData("hasProxyDescendant", False))
return (self.interface.getUserData("hasConcreteDescendant", False)
or self.interface.getUserData("hasProxyDescendant", False))

def hasHTMLConstructor(self):
ctor = self.interface.ctor()
Expand All @@ -402,8 +413,8 @@ def shouldHaveGetConstructorObjectMethod(self):
assert self.interface.hasInterfaceObject()
if self.interface.getExtendedAttribute("Inline"):
return False
return (self.interface.isCallback() or self.interface.isNamespace() or
self.hasDescendants() or self.hasHTMLConstructor())
return (self.interface.isCallback() or self.interface.isNamespace()
or self.hasDescendants() or self.hasHTMLConstructor())

def shouldCacheConstructor(self):
return self.hasDescendants() or self.hasHTMLConstructor()
Expand All @@ -416,8 +427,8 @@ def isGlobal(self):
Returns true if this is the primary interface for a global object
of some sort.
"""
return bool(self.interface.getExtendedAttribute("Global") or
self.interface.getExtendedAttribute("PrimaryGlobal"))
return bool(self.interface.getExtendedAttribute("Global")
or self.interface.getExtendedAttribute("PrimaryGlobal"))


# Some utility methods
Expand All @@ -428,8 +439,8 @@ def MakeNativeName(name):


def getModuleFromObject(object):
return ('crate::dom::bindings::codegen::Bindings::' +
os.path.basename(object.location.filename()).split('.webidl')[0] + 'Binding')
return ('crate::dom::bindings::codegen::Bindings::'
+ os.path.basename(object.location.filename()).split('.webidl')[0] + 'Binding')


def getTypesFromDescriptor(descriptor):
Expand Down
10 changes: 5 additions & 5 deletions components/style/properties/data.py
Expand Up @@ -198,11 +198,11 @@ def __init__(self, style_struct, name, spec=None, animation_value_type=None, key
self.gecko_pref = gecko_pref
self.has_effect_on_gecko_scrollbars = has_effect_on_gecko_scrollbars
assert (
has_effect_on_gecko_scrollbars in [None, False, True] and
not style_struct.inherited or
(gecko_pref is None) == (has_effect_on_gecko_scrollbars is None)), (
"Property " + name + ": has_effect_on_gecko_scrollbars must be " +
"specified, and must have a value of True or False, iff a " +
has_effect_on_gecko_scrollbars in [None, False, True]
and not style_struct.inherited
or (gecko_pref is None) == (has_effect_on_gecko_scrollbars is None)), (
"Property " + name + ": has_effect_on_gecko_scrollbars must be "
"specified, and must have a value of True or False, iff a "
"property is inherited and is behind a Gecko pref")
# For enabled_in, the setup is as follows:
# It needs to be one of the four values: ["", "ua", "chrome", "content"]
Expand Down
2 changes: 1 addition & 1 deletion etc/ci/check_dynamic_symbols.py
Expand Up @@ -14,7 +14,7 @@
import subprocess
import sys

symbol_regex = re.compile(b"D \*UND\*\t(.*) (.*)$")
symbol_regex = re.compile(br"D \*UND\*\t(.*) (.*)$")
allowed_symbols = frozenset([
b'unshare',
b'malloc_usable_size',
Expand Down
78 changes: 39 additions & 39 deletions etc/ci/performance/gecko_driver.py
Expand Up @@ -31,44 +31,44 @@ def create_gecko_session():


def generate_placeholder(testcase):
# We need to still include the failed tests, otherwise Treeherder will
# consider the result to be a new test series, and thus a new graph. So we
# use a placeholder with values = -1 to make Treeherder happy, and still be
# able to identify failed tests (successful tests have time >=0).

timings = {
"testcase": testcase,
"title": ""
}

timing_names = [
"navigationStart",
"unloadEventStart",
"domLoading",
"fetchStart",
"responseStart",
"loadEventEnd",
"connectStart",
"domainLookupStart",
"redirectStart",
"domContentLoadedEventEnd",
"requestStart",
"secureConnectionStart",
"connectEnd",
"loadEventStart",
"domInteractive",
"domContentLoadedEventStart",
"redirectEnd",
"domainLookupEnd",
"unloadEventEnd",
"responseEnd",
"domComplete",
]

for name in timing_names:
timings[name] = 0 if name == "navigationStart" else -1

return [timings]
# We need to still include the failed tests, otherwise Treeherder will
# consider the result to be a new test series, and thus a new graph. So we
# use a placeholder with values = -1 to make Treeherder happy, and still be
# able to identify failed tests (successful tests have time >=0).

timings = {
"testcase": testcase,
"title": ""
}

timing_names = [
"navigationStart",
"unloadEventStart",
"domLoading",
"fetchStart",
"responseStart",
"loadEventEnd",
"connectStart",
"domainLookupStart",
"redirectStart",
"domContentLoadedEventEnd",
"requestStart",
"secureConnectionStart",
"connectEnd",
"loadEventStart",
"domInteractive",
"domContentLoadedEventStart",
"redirectEnd",
"domainLookupEnd",
"unloadEventEnd",
"responseEnd",
"domComplete",
]

for name in timing_names:
timings[name] = 0 if name == "navigationStart" else -1

return [timings]


def run_gecko_test(testcase, url, date, timeout, is_async):
Expand All @@ -91,7 +91,7 @@ def run_gecko_test(testcase, url, date, timeout, is_async):
"return JSON.stringify(performance.timing)"
)
))
except:
except Exception:
# We need to return a timing object no matter what happened.
# See the comment in generate_placeholder() for explanation
print("Failed to get a valid timing measurement.")
Expand Down
10 changes: 5 additions & 5 deletions etc/ci/performance/runner.py
Expand Up @@ -116,7 +116,7 @@ def parse_block(block):
for line in block:
try:
(_, key, value) = line.split(",")
except:
except ValueError:
print("[DEBUG] failed to parse the following line:")
print(line)
print('[DEBUG] log:')
Expand All @@ -133,10 +133,10 @@ def parse_block(block):
return timing

def valid_timing(timing, url=None):
if (timing is None or
testcase is None or
timing.get('title') == 'Error loading page' or
timing.get('testcase') != url):
if (timing is None
or testcase is None
or timing.get('title') == 'Error loading page'
or timing.get('testcase') != url):
return False
else:
return True
Expand Down
4 changes: 2 additions & 2 deletions etc/ci/performance/submit_to_perfherder.py
Expand Up @@ -19,8 +19,8 @@


def geometric_mean(iterable):
filtered = list(filter(lambda x: x > 0, iterable))
return (reduce(operator.mul, filtered)) ** (1.0 / len(filtered))
filtered = list(filter(lambda x: x > 0, iterable))
return (reduce(operator.mul, filtered)) ** (1.0 / len(filtered))


def format_testcase_name(name):
Expand Down
1 change: 1 addition & 0 deletions etc/ci/performance/test_differ.py
Expand Up @@ -29,6 +29,7 @@ def load_data(filename):
results[key] = round(totals[key] / counts[key])
return results


data1 = load_data(args.file1)
data2 = load_data(args.file2)
keys = set(data1.keys()).union(data2.keys())
Expand Down
4 changes: 2 additions & 2 deletions etc/ci/performance/test_submit_to_perfherder.py
Expand Up @@ -14,8 +14,8 @@ def test_format_testcase_name():
'http://localhost:8000/page_load_test/163.com/p.mail.163.com/'
'mailinfo/shownewmsg_www_1222.htm.html')))
assert(('1234567890223456789032345678904234567890'
'5234567890623456789072345678908234567890') ==
submit_to_perfherder.format_testcase_name((
'5234567890623456789072345678908234567890')
== submit_to_perfherder.format_testcase_name((
'1234567890223456789032345678904234567890'
'52345678906234567890723456789082345678909234567890')))
assert('news.ycombinator.com' == submit_to_perfherder.format_testcase_name(
Expand Down
6 changes: 3 additions & 3 deletions etc/servo_automation_screenshot.py
Expand Up @@ -10,15 +10,14 @@
"""
Created on Mon Mar 26 20:08:25 2018
@author: Pranshu Sinha, Abhay Soni, Aayushi Agrawal
"""
"""
The below program is intended to test rendering mismatches in servo by taking screenshots of rendered html files.
Here is the breakdown of how our code works:
* A session is started on localhost:7002
* The randomly generated webpage's (html files) data is sent as JSON to this session
* Using curl request, we load the html files for this session ID based on the session we just created.
"""

import os
import json
import requests
Expand Down Expand Up @@ -72,7 +71,7 @@ def render_html_files(num_of_files, url, file_url, json_string, headers, cwd):
image_file.write(base64.decodebytes(image_data_encoded.encode('utf-8')))
print("################################")
print("The screenshot is stored in the location: {0}/screenshots/"
+ " with filename: output_image_{1}.png".format(cwd, str(x)))
" with filename: output_image_{1}.png".format(cwd, str(x)))
print("################################")


Expand Down Expand Up @@ -124,6 +123,7 @@ def main(argv): # take inputs from command line by considering the options para
# Render each HTML file and take a screenshot
render_html_files(num_of_files, url, file_url, json_string, headers, cwd)


if __name__ == "__main__":
if len(sys.argv) < 8:
print_help()
Expand Down
1 change: 1 addition & 0 deletions etc/servo_gdb.py
Expand Up @@ -128,6 +128,7 @@ def __init__(self, val):
def to_string(self):
return "[UNKNOWN - type = {0}]".format(str(self.val.type))


type_map = [
('struct Au', AuPrinter),
('FlowFlags', BitFieldU8Printer),
Expand Down
7 changes: 3 additions & 4 deletions etc/taskcluster/mock.py
Expand Up @@ -13,15 +13,14 @@
python3 -m coverage run $0
python3 -m coverage report -m --fail-under 100
exit
'''

"""
Run the decision task with fake Taskcluster APIs, to catch Python errors before pushing.
"""
'''
import os
import sys
from unittest.mock import MagicMock
import decision_task
class TaskclusterRestFailure(Exception):
Expand All @@ -47,7 +46,7 @@ def findTask(self, path):
os.environ["TASKCLUSTER_ROOT_URL"] = "https://community-tc.services.mozilla.com"
os.environ["TASKCLUSTER_PROXY_URL"] = "http://taskcluster"
os.environ["NEW_AMI_WORKER_TYPE"] = "-"
import decision_task
decision_task.decisionlib.subprocess = MagicMock()
print("\n# Push:")
Expand Down

0 comments on commit d01648d

Please sign in to comment.