From 2ffb772261814d36375f210033bd5ec9f78663e0 Mon Sep 17 00:00:00 2001 From: symonk Date: Mon, 2 Oct 2023 21:06:13 +0100 Subject: [PATCH] [py]: use lazy string interpolation for logging calls --- py/selenium/webdriver/common/bidi/cdp.py | 4 ++-- py/selenium/webdriver/common/selenium_manager.py | 8 ++++---- py/selenium/webdriver/common/service.py | 2 +- py/selenium/webdriver/remote/remote_connection.py | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/py/selenium/webdriver/common/bidi/cdp.py b/py/selenium/webdriver/common/bidi/cdp.py index db11eac9882de..7fec0de1b8dae 100644 --- a/py/selenium/webdriver/common/bidi/cdp.py +++ b/py/selenium/webdriver/common/bidi/cdp.py @@ -65,7 +65,7 @@ def import_devtools(ver): versions = tuple(f.name for f in devtools_path.iterdir() if f.is_dir()) latest = max(int(x[1:]) for x in versions) selenium_logger = logging.getLogger(__name__) - selenium_logger.debug(f"Falling back to loading `devtools`: v{latest}") + selenium_logger.debug("Falling back to loading `devtools`: v%s", latest) devtools = importlib.import_module(f"{base}{latest}") return devtools @@ -265,7 +265,7 @@ def _handle_cmd_response(self, data): try: cmd, event = self.inflight_cmd.pop(cmd_id) except KeyError: - logger.warning(f"Got a message with a command ID that does not exist: {data}") + logger.warning("Got a message with a command ID that does not exist: %s", data) return if "error" in data: # If the server reported an error, convert it to an exception and do diff --git a/py/selenium/webdriver/common/selenium_manager.py b/py/selenium/webdriver/common/selenium_manager.py index 72d3e46cd61cf..73085fd8e9f69 100644 --- a/py/selenium/webdriver/common/selenium_manager.py +++ b/py/selenium/webdriver/common/selenium_manager.py @@ -60,11 +60,11 @@ def get_binary() -> Path: if not path.is_file() and os.environ["CONDA_PREFIX"]: # conda has a separate package selenium-manager, installs in bin path = Path(os.path.join(os.environ["CONDA_PREFIX"], "bin", file)) - logger.debug(f"Conda environment detected, using `{path}`") + logger.debug("Conda environment detected, using `%s`", path) if not path.is_file(): raise WebDriverException(f"Unable to obtain working Selenium Manager binary; {path}") - logger.debug(f"Selenium Manager binary found at: {path}") + logger.debug("Selenium Manager binary found at: %s", path) return path @@ -99,7 +99,7 @@ def driver_location(self, options: BaseOptions) -> str: browser_path = output["browser_path"] driver_path = output["driver_path"] - logger.debug(f"Using driver at: {driver_path}") + logger.debug("Using driver at: %s", driver_path) if hasattr(options.__class__, "binary_location"): options.binary_location = browser_path @@ -121,7 +121,7 @@ def run(args: List[str]) -> dict: args.append("json") command = " ".join(args) - logger.debug(f"Executing process: {command}") + logger.debug("Executing process: %s", command) try: if sys.platform == "win32": completed_proc = subprocess.run(args, capture_output=True, creationflags=subprocess.CREATE_NO_WINDOW) diff --git a/py/selenium/webdriver/common/service.py b/py/selenium/webdriver/common/service.py index 54fcfc7367e87..395a098155c53 100644 --- a/py/selenium/webdriver/common/service.py +++ b/py/selenium/webdriver/common/service.py @@ -212,7 +212,7 @@ def _start_process(self, path: str) -> None: startupinfo=start_info, **self.popen_kw, ) - logger.debug(f"Started executable: `{self._path}` in a child process with pid: {self.process.pid}") + logger.debug("Started executable: `%s` in a child process with pid: %s", self._path, self.process.pid) except TypeError: raise except OSError as err: diff --git a/py/selenium/webdriver/remote/remote_connection.py b/py/selenium/webdriver/remote/remote_connection.py index 870d51d511f59..bf288deb7715c 100644 --- a/py/selenium/webdriver/remote/remote_connection.py +++ b/py/selenium/webdriver/remote/remote_connection.py @@ -307,7 +307,7 @@ def _request(self, method, url, body=None): :Returns: A dictionary with the server's parsed JSON response. """ - LOGGER.debug(f"{method} {url} {body}") + LOGGER.debug("%s %s %s", method, url, body) parsed_url = parse.urlparse(url) headers = self.get_remote_connection_headers(parsed_url, self.keep_alive) response = None @@ -323,7 +323,7 @@ def _request(self, method, url, body=None): response = http.request(method, url, body=body, headers=headers) statuscode = response.status data = response.data.decode("UTF-8") - LOGGER.debug(f"Remote response: status={response.status} | data={data} | headers={response.headers}") + LOGGER.debug("Remote response: status=%s | data=%s | headers=%s", response.status, data, response.headers) try: if 300 <= statuscode < 304: return self._request("GET", response.headers.get("location", None))