diff --git a/choreographer/browser_async.py b/choreographer/browser_async.py index f8d78a2a..2b272597 100644 --- a/choreographer/browser_async.py +++ b/choreographer/browser_async.py @@ -24,7 +24,9 @@ from collections.abc import Generator, MutableMapping from pathlib import Path from types import TracebackType - from typing import Any, Self + from typing import Any + + from typing_extensions import Self # 3.9 needs this, could be from typing in 3.10 from .browsers._interface_type import BrowserImplInterface from .channels._interface_type import ChannelInterface diff --git a/choreographer/browser_sync.py b/choreographer/browser_sync.py index 27dcf0ad..cfa271ba 100644 --- a/choreographer/browser_sync.py +++ b/choreographer/browser_sync.py @@ -19,7 +19,9 @@ from collections.abc import MutableMapping from pathlib import Path from types import TracebackType - from typing import Any, Self + from typing import Any + + from typing_extensions import Self # 3.9 needs this, could be from typing in 3.10 from .browsers._interface_type import BrowserImplInterface from .channels._interface_type import ChannelInterface diff --git a/choreographer/channels/pipe.py b/choreographer/channels/pipe.py index 7384fd06..e500dde8 100644 --- a/choreographer/channels/pipe.py +++ b/choreographer/channels/pipe.py @@ -70,7 +70,7 @@ def write_json(self, obj: Mapping[str, Any]) -> None: if self.shutdown_lock.locked(): raise ChannelClosedError encoded_message = wire.serialize(obj) + b"\0" - _logger.debug2(f"Writing: {encoded_message}") + _logger.debug2(f"Writing: {encoded_message!r}") try: os.write(self._write_to_browser, encoded_message) except OSError as e: @@ -112,7 +112,7 @@ def read_jsons( # noqa: PLR0912, C901 branches, complexity self._read_from_browser, 10000, ) # 10MB buffer, nbd, doesn't matter w/ this - _logger.debug2(f"Read: {raw_buffer}") + _logger.debug2(f"Read: {raw_buffer!r}") if not raw_buffer or raw_buffer == b"{bye}\n": # we seem to need {bye} even if chrome closes NOTE raise ChannelClosedError @@ -121,7 +121,7 @@ def read_jsons( # noqa: PLR0912, C901 branches, complexity if _with_block: os.set_blocking(self._read_from_browser, True) raw_buffer += os.read(self._read_from_browser, 10000) - _logger.debug2(f"Read: {raw_buffer}") + _logger.debug2(f"Read: {raw_buffer!r}") except BlockingIOError: return jsons except OSError as e: diff --git a/choreographer/cli/_cli_utils_no_qa.py b/choreographer/cli/_cli_utils_no_qa.py index ae374e88..78d9506b 100644 --- a/choreographer/cli/_cli_utils_no_qa.py +++ b/choreographer/cli/_cli_utils_no_qa.py @@ -107,7 +107,11 @@ def diagnose() -> None: for exception in fail: try: print(f"Error in: {exception[0]}") - traceback.print_exception(exception[1]) + traceback.print_exception( + type(exception[1]), + exception[1], + exception[1].__traceback__, + ) except BaseException: print("Couldn't print traceback for:") print(str(exception)) diff --git a/choreographer/protocol/__init__.py b/choreographer/protocol/__init__.py index 7556f8cc..fa76b712 100644 --- a/choreographer/protocol/__init__.py +++ b/choreographer/protocol/__init__.py @@ -8,14 +8,14 @@ from collections.abc import MutableMapping from enum import Enum -from typing import Any, NewType, cast +from typing import Any, NewType, Optional, cast BrowserResponse = NewType("BrowserResponse", MutableMapping[str, Any]) """The type for a response from the browser. Is really a `dict()`.""" BrowserCommand = NewType("BrowserCommand", MutableMapping[str, Any]) """The type for a command to the browser. Is really a `dict()`.""" -MessageKey = NewType("MessageKey", tuple[str, int | None]) +MessageKey = NewType("MessageKey", tuple[str, Optional[int]]) """The type for id'ing a message/response. It is `tuple(session_id, message_id)`.""" diff --git a/choreographer/utils/_tmpfile.py b/choreographer/utils/_tmpfile.py index d336ca14..339ab05d 100644 --- a/choreographer/utils/_tmpfile.py +++ b/choreographer/utils/_tmpfile.py @@ -64,13 +64,13 @@ def __init__(self, path: str | None = None, *, sneak: bool = False): else: # is windows vinfo = sys.version_info[:3] if vinfo >= (3, 12): - self.temp_dir = tempfile.TemporaryDirectory( + self.temp_dir = tempfile.TemporaryDirectory( # type: ignore [call-overload, unused-ignore] delete=False, ignore_cleanup_errors=True, **args, ) elif vinfo >= (3, 10): - self.temp_dir = tempfile.TemporaryDirectory( + self.temp_dir = tempfile.TemporaryDirectory( # type: ignore [call-overload, unused-ignore] ignore_cleanup_errors=True, **args, ) @@ -170,7 +170,7 @@ def remove_readonly( try: if self._with_onexc: - shutil.rmtree(self.path, onexc=remove_readonly) + shutil.rmtree(self.path, onexc=remove_readonly) # type: ignore [call-arg, unused-ignore] else: shutil.rmtree(self.path, onerror=remove_readonly) self.exists = False