Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve version changes in typing #182

Merged
merged 1 commit into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion choreographer/browser_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion choreographer/browser_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions choreographer/channels/pipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion choreographer/cli/_cli_utils_no_qa.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions choreographer/protocol/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)`."""


Expand Down
6 changes: 3 additions & 3 deletions choreographer/utils/_tmpfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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
Expand Down