Skip to content

Commit 325982f

Browse files
authored
Merge pull request #182 from plotly/andrew/typing
Improve version changes in typing
2 parents ac2124e + 1caf7e1 commit 325982f

File tree

6 files changed

+19
-11
lines changed

6 files changed

+19
-11
lines changed

choreographer/browser_async.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
from collections.abc import Generator, MutableMapping
2525
from pathlib import Path
2626
from types import TracebackType
27-
from typing import Any, Self
27+
from typing import Any
28+
29+
from typing_extensions import Self # 3.9 needs this, could be from typing in 3.10
2830

2931
from .browsers._interface_type import BrowserImplInterface
3032
from .channels._interface_type import ChannelInterface

choreographer/browser_sync.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
from collections.abc import MutableMapping
2020
from pathlib import Path
2121
from types import TracebackType
22-
from typing import Any, Self
22+
from typing import Any
23+
24+
from typing_extensions import Self # 3.9 needs this, could be from typing in 3.10
2325

2426
from .browsers._interface_type import BrowserImplInterface
2527
from .channels._interface_type import ChannelInterface

choreographer/channels/pipe.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def write_json(self, obj: Mapping[str, Any]) -> None:
7070
if self.shutdown_lock.locked():
7171
raise ChannelClosedError
7272
encoded_message = wire.serialize(obj) + b"\0"
73-
_logger.debug2(f"Writing: {encoded_message}")
73+
_logger.debug2(f"Writing: {encoded_message!r}")
7474
try:
7575
os.write(self._write_to_browser, encoded_message)
7676
except OSError as e:
@@ -112,7 +112,7 @@ def read_jsons( # noqa: PLR0912, C901 branches, complexity
112112
self._read_from_browser,
113113
10000,
114114
) # 10MB buffer, nbd, doesn't matter w/ this
115-
_logger.debug2(f"Read: {raw_buffer}")
115+
_logger.debug2(f"Read: {raw_buffer!r}")
116116
if not raw_buffer or raw_buffer == b"{bye}\n":
117117
# we seem to need {bye} even if chrome closes NOTE
118118
raise ChannelClosedError
@@ -121,7 +121,7 @@ def read_jsons( # noqa: PLR0912, C901 branches, complexity
121121
if _with_block:
122122
os.set_blocking(self._read_from_browser, True)
123123
raw_buffer += os.read(self._read_from_browser, 10000)
124-
_logger.debug2(f"Read: {raw_buffer}")
124+
_logger.debug2(f"Read: {raw_buffer!r}")
125125
except BlockingIOError:
126126
return jsons
127127
except OSError as e:

choreographer/cli/_cli_utils_no_qa.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,11 @@ def diagnose() -> None:
107107
for exception in fail:
108108
try:
109109
print(f"Error in: {exception[0]}")
110-
traceback.print_exception(exception[1])
110+
traceback.print_exception(
111+
type(exception[1]),
112+
exception[1],
113+
exception[1].__traceback__,
114+
)
111115
except BaseException:
112116
print("Couldn't print traceback for:")
113117
print(str(exception))

choreographer/protocol/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88

99
from collections.abc import MutableMapping
1010
from enum import Enum
11-
from typing import Any, NewType, cast
11+
from typing import Any, NewType, Optional, cast
1212

1313
BrowserResponse = NewType("BrowserResponse", MutableMapping[str, Any])
1414
"""The type for a response from the browser. Is really a `dict()`."""
1515
BrowserCommand = NewType("BrowserCommand", MutableMapping[str, Any])
1616
"""The type for a command to the browser. Is really a `dict()`."""
1717

18-
MessageKey = NewType("MessageKey", tuple[str, int | None])
18+
MessageKey = NewType("MessageKey", tuple[str, Optional[int]])
1919
"""The type for id'ing a message/response. It is `tuple(session_id, message_id)`."""
2020

2121

choreographer/utils/_tmpfile.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ def __init__(self, path: str | None = None, *, sneak: bool = False):
6464
else: # is windows
6565
vinfo = sys.version_info[:3]
6666
if vinfo >= (3, 12):
67-
self.temp_dir = tempfile.TemporaryDirectory(
67+
self.temp_dir = tempfile.TemporaryDirectory( # type: ignore [call-overload, unused-ignore]
6868
delete=False,
6969
ignore_cleanup_errors=True,
7070
**args,
7171
)
7272
elif vinfo >= (3, 10):
73-
self.temp_dir = tempfile.TemporaryDirectory(
73+
self.temp_dir = tempfile.TemporaryDirectory( # type: ignore [call-overload, unused-ignore]
7474
ignore_cleanup_errors=True,
7575
**args,
7676
)
@@ -170,7 +170,7 @@ def remove_readonly(
170170

171171
try:
172172
if self._with_onexc:
173-
shutil.rmtree(self.path, onexc=remove_readonly)
173+
shutil.rmtree(self.path, onexc=remove_readonly) # type: ignore [call-arg, unused-ignore]
174174
else:
175175
shutil.rmtree(self.path, onerror=remove_readonly)
176176
self.exists = False

0 commit comments

Comments
 (0)