|
10 | 10 | from io import SEEK_SET, UnsupportedOperation |
11 | 11 | from os import PathLike |
12 | 12 | from pathlib import Path |
13 | | -from typing import Any, BinaryIO, cast |
| 13 | +from typing import IO, Any |
14 | 14 |
|
15 | 15 | from .. import ( |
16 | 16 | BrokenResourceError, |
|
25 | 25 |
|
26 | 26 | class FileStreamAttribute(TypedAttributeSet): |
27 | 27 | #: the open file descriptor |
28 | | - file: BinaryIO = typed_attribute() |
| 28 | + file: IO[bytes] = typed_attribute() |
29 | 29 | #: the path of the file on the file system, if available (file must be a real file) |
30 | 30 | path: Path = typed_attribute() |
31 | 31 | #: the file number, if available (file must be a real file or a TTY) |
32 | 32 | fileno: int = typed_attribute() |
33 | 33 |
|
34 | 34 |
|
35 | 35 | class _BaseFileStream: |
36 | | - def __init__(self, file: BinaryIO): |
| 36 | + def __init__(self, file: IO[bytes]): |
37 | 37 | self._file = file |
38 | 38 |
|
39 | 39 | async def aclose(self) -> None: |
@@ -76,7 +76,7 @@ async def from_path(cls, path: str | PathLike[str]) -> FileReadStream: |
76 | 76 |
|
77 | 77 | """ |
78 | 78 | file = await to_thread.run_sync(Path(path).open, "rb") |
79 | | - return cls(cast(BinaryIO, file)) |
| 79 | + return cls(file) |
80 | 80 |
|
81 | 81 | async def receive(self, max_bytes: int = 65536) -> bytes: |
82 | 82 | try: |
@@ -143,7 +143,7 @@ async def from_path( |
143 | 143 | """ |
144 | 144 | mode = "ab" if append else "wb" |
145 | 145 | file = await to_thread.run_sync(Path(path).open, mode) |
146 | | - return cls(cast(BinaryIO, file)) |
| 146 | + return cls(file) |
147 | 147 |
|
148 | 148 | async def send(self, item: bytes) -> None: |
149 | 149 | try: |
|
0 commit comments