diff --git a/common/devtools/convert_protocol_to_json.py b/common/devtools/convert_protocol_to_json.py index cfea7867d4ef0..c82c838a1c8c6 100644 --- a/common/devtools/convert_protocol_to_json.py +++ b/common/devtools/convert_protocol_to_json.py @@ -21,7 +21,7 @@ def main(argv): parser.add_argument("json_file", help="The .json output file write.") args = parser.parse_args(argv) file_name = os.path.normpath(args.pdl_file) - input_file = open(file_name, "r") + input_file = open(file_name) pdl_string = input_file.read() protocol = pdl.loads(pdl_string, file_name, args.map_binary_to_string) input_file.close() diff --git a/common/devtools/pdl.py b/common/devtools/pdl.py index 132615b6835e1..fce9012156768 100644 --- a/common/devtools/pdl.py +++ b/common/devtools/pdl.py @@ -2,7 +2,6 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -from __future__ import print_function import collections import json import re @@ -166,7 +165,7 @@ def parse(data, file_name, map_binary_to_string=False): enumliterals.append(trimLine) continue - print('Error in %s:%s, illegal token: \t%s' % (file_name, i, line)) + print(f'Error in {file_name}:{i}, illegal token: \t{line}') sys.exit(1) return protocol diff --git a/javascript/private/gen_file.py b/javascript/private/gen_file.py index 42d6d520185b5..e5df94a5650fa 100644 --- a/javascript/private/gen_file.py +++ b/javascript/private/gen_file.py @@ -38,7 +38,7 @@ def write_atom_literal(out, name, contents, lang, utf8): else: line_format = " L\"{}\",\n" elif "java" == lang: - line_format = " .append\(\"{}\")\n" + line_format = " .append\\(\"{}\")\n" else: raise RuntimeError("Unknown language: %s " % lang) @@ -47,7 +47,7 @@ def write_atom_literal(out, name, contents, lang, utf8): if "cc" == lang or "hh" == lang: string_type = "std::string" if utf8 else "std::wstring" char_type = "char" if utf8 else "wchar_t" - out.write("const %s* const %s[] = {\n" % (char_type, name)) + out.write(f"const {char_type}* const {name}[] = {{\n") elif "java" == lang: out.write(" %s(new StringBuilder()\n" % name) else: @@ -75,43 +75,43 @@ def write_atom_literal(out, name, contents, lang, utf8): def generate_header(file_name, out, js_map, just_declare, utf8): define_guard = "WEBDRIVER_%s" % os.path.basename(file_name.upper()).replace(".", "_") include_stddef = "" if utf8 else "\n#include // For wchar_t." - out.write("""%s + out.write("""{} /* AUTO GENERATED - DO NOT EDIT BY HAND */ -#ifndef %s -#define %s -%s +#ifndef {} +#define {} +{} #include // For std::(w)string. -namespace webdriver { -namespace atoms { +namespace webdriver {{ +namespace atoms {{ -""" % (_copyright, define_guard, define_guard, include_stddef)) +""".format(_copyright, define_guard, define_guard, include_stddef)) string_type = "std::string" if utf8 else "std::wstring" char_type = "char" if utf8 else "wchar_t" for (name, file) in js_map.items(): if just_declare: - out.write("extern const %s* const %s[];\n" % (char_type, name.upper())) + out.write(f"extern const {char_type}* const {name.upper()}[];\n") else: - contents = open(file, "r").read() + contents = open(file).read() write_atom_literal(out, name, contents, "hh", utf8) out.write(""" -static inline %s asString(const %s* const atom[]) { - %s source; - for (int i = 0; atom[i] != NULL; i++) { +static inline {} asString(const {}* const atom[]) {{ + {} source; + for (int i = 0; atom[i] != NULL; i++) {{ source += atom[i]; - } + }} return source; -} +}} -} // namespace atoms -} // namespace webdriver +}} // namespace atoms +}} // namespace webdriver -#endif // %s -""" % (string_type, char_type, string_type, define_guard)) +#endif // {} +""".format(string_type, char_type, string_type, define_guard)) def generate_cc_source(out, js_map, utf8): out.write("""%s @@ -127,7 +127,7 @@ def generate_cc_source(out, js_map, utf8): """ % _copyright) for (name, file) in js_map.items(): - contents = open(file, "r").read() + contents = open(file).read() write_atom_literal(out, name, contents, "cc", utf8) out.write(""" @@ -152,7 +152,7 @@ def generate_java_source(file_name, out, preamble, js_map): """ % class_name) for (name, file) in js_map.items(): - contents = open(file, "r").read() + contents = open(file).read() write_atom_literal(out, name, contents, "java", True) out.write(""" diff --git a/py/selenium/webdriver/remote/webelement.py b/py/selenium/webdriver/remote/webelement.py index e5a3adad0d7b4..b11b17202dfbe 100644 --- a/py/selenium/webdriver/remote/webelement.py +++ b/py/selenium/webdriver/remote/webelement.py @@ -25,7 +25,6 @@ from base64 import encodebytes from hashlib import md5 as md5_hash from io import BytesIO -from typing import List from selenium.common.exceptions import JavascriptException from selenium.common.exceptions import WebDriverException @@ -414,7 +413,7 @@ def find_element(self, by=By.ID, value=None) -> WebElement: by, value = self._parent.locator_converter.convert(by, value) return self._execute(Command.FIND_CHILD_ELEMENT, {"using": by, "value": value})["value"] - def find_elements(self, by=By.ID, value=None) -> List[WebElement]: + def find_elements(self, by=By.ID, value=None) -> list[WebElement]: """Find elements given a By strategy and locator. :Usage: diff --git a/py/test/selenium/webdriver/remote/remote_downloads_tests.py b/py/test/selenium/webdriver/remote/remote_downloads_tests.py index 72ac2a4fc8ba5..555c4e52dba88 100644 --- a/py/test/selenium/webdriver/remote/remote_downloads_tests.py +++ b/py/test/selenium/webdriver/remote/remote_downloads_tests.py @@ -38,7 +38,7 @@ def test_download_file(driver, pages): driver.download_file(file_name, target_directory) target_file = os.path.join(target_directory, file_name) - with open(target_file, "r") as file: + with open(target_file) as file: assert "Hello, World!" in file.read() diff --git a/scripts/pinned_browsers.py b/scripts/pinned_browsers.py index b41b169577f46..e2a7bce970780 100755 --- a/scripts/pinned_browsers.py +++ b/scripts/pinned_browsers.py @@ -117,8 +117,8 @@ def chrome(selected_version): content = """ http_archive( name = "linux_chrome", - url = "%s", - sha256 = "%s", + url = "{}", + sha256 = "{}", build_file_content = \"\"\" load("@aspect_rules_js//js:defs.bzl", "js_library") package(default_visibility = ["//visibility:public"]) @@ -137,7 +137,7 @@ def chrome(selected_version): \"\"\", ) -""" % ( +""".format( linux, sha, ) @@ -147,8 +147,8 @@ def chrome(selected_version): content += """ http_archive( name = "mac_chrome", - url = "%s", - sha256 = "%s", + url = "{}", + sha256 = "{}", strip_prefix = "chrome-mac-x64", patch_cmds = [ "mv 'Google Chrome for Testing.app' Chrome.app", @@ -167,7 +167,7 @@ def chrome(selected_version): \"\"\", ) -""" % ( +""".format( mac, sha, ) @@ -206,11 +206,11 @@ def edge(): content += """ pkg_archive( name = "mac_edge", - url = "%s", - sha256 = "%s", - move = { - "MicrosoftEdge-%s.pkg/Payload/Microsoft Edge.app": "Edge.app", - }, + url = "{}", + sha256 = "{}", + move = {{ + "MicrosoftEdge-{}.pkg/Payload/Microsoft Edge.app": "Edge.app", + }}, build_file_content = \"\"\" load("@aspect_rules_js//js:defs.bzl", "js_library") package(default_visibility = ["//visibility:public"]) @@ -223,7 +223,7 @@ def edge(): ) \"\"\", ) -""" % ( +""".format( mac, mac_hash.lower(), mac_version, @@ -233,8 +233,8 @@ def edge(): content += """ deb_archive( name = "linux_edge", - url = "%s", - sha256 = "%s", + url = "{}", + sha256 = "{}", build_file_content = \"\"\" load("@aspect_rules_js//js:defs.bzl", "js_library") package(default_visibility = ["//visibility:public"]) @@ -252,7 +252,7 @@ def edge(): ) \"\"\", ) -""" % ( +""".format( linux, linux_hash.lower() ) @@ -402,11 +402,11 @@ def firefox_version_data(): def firefox_linux(version): - return "https://ftp.mozilla.org/pub/firefox/releases/%s/linux-x86_64/en-US/firefox-%s.tar.bz2" % (version, version) + return f"https://ftp.mozilla.org/pub/firefox/releases/{version}/linux-x86_64/en-US/firefox-{version}.tar.bz2" def firefox_mac(version): - return "https://ftp.mozilla.org/pub/firefox/releases/%s/mac/en-US/Firefox%%20%s.dmg" % (version, version) + return f"https://ftp.mozilla.org/pub/firefox/releases/{version}/mac/en-US/Firefox%20{version}.dmg" def print_firefox(version, workspace_name, sha_linux, sha_mac): diff --git a/scripts/update_copyright.py b/scripts/update_copyright.py index e1af49ec80ce2..04cea63a77875 100755 --- a/scripts/update_copyright.py +++ b/scripts/update_copyright.py @@ -28,7 +28,7 @@ def __init__(self, comment_characters='//', prefix=None): def update(self, files): for file in files: - with open(file, 'r', encoding='utf-8-sig') as f: + with open(file, encoding='utf-8-sig') as f: lines = f.readlines() index = -1