-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
typing: accept buffers in typing.IO.write #9084
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
Changes from 7 commits
2f87ea0
e940cdf
8d82f82
5aacf0a
9293f5e
717e864
2894148
6532cd4
642f843
641511b
590851b
b6174cb
92c2606
7f10fc8
684b4ee
bd78b5b
37bb27e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,7 +101,7 @@ class HTTPMessage(email.message.Message): | |
|
||
def parse_headers(fp: io.BufferedIOBase, _class: Callable[[], email.message.Message] = ...) -> HTTPMessage: ... | ||
|
||
class HTTPResponse(io.BufferedIOBase, BinaryIO): | ||
class HTTPResponse(io.BufferedIOBase, BinaryIO): # type: ignore[misc] # https://github.com/python/mypy/issues/14002 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do still need this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated these comments. |
||
msg: HTTPMessage | ||
headers: HTTPMessage | ||
version: int | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import io | ||
import sys | ||
from _typeshed import BytesPath, GenericPath, Self, StrPath, WriteableBuffer | ||
from _typeshed import BytesPath, GenericPath, ReadableBuffer, Self, StrPath, WriteableBuffer | ||
from collections.abc import Iterable, Iterator | ||
from types import TracebackType | ||
from typing import IO, Any, AnyStr, Generic, overload | ||
|
@@ -215,8 +215,14 @@ class _TemporaryFileWrapper(Generic[AnyStr], IO[AnyStr]): | |
def tell(self) -> int: ... | ||
def truncate(self, size: int | None = ...) -> int: ... | ||
def writable(self) -> bool: ... | ||
def write(self, s: AnyStr) -> int: ... | ||
def writelines(self, lines: Iterable[AnyStr]) -> None: ... | ||
@overload | ||
def write(self: _TemporaryFileWrapper[str], s: str) -> int: ... | ||
@overload | ||
def write(self: _TemporaryFileWrapper[bytes], s: ReadableBuffer) -> int: ... | ||
@overload | ||
def writelines(self: _TemporaryFileWrapper[str], lines: Iterable[str]) -> None: ... | ||
@overload | ||
def writelines(self: _TemporaryFileWrapper[bytes], lines: Iterable[ReadableBuffer]) -> None: ... | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed, and added some testcases for |
||
|
||
if sys.version_info >= (3, 11): | ||
_SpooledTemporaryFileBase = io.IOBase | ||
|
@@ -392,8 +398,14 @@ class SpooledTemporaryFile(IO[AnyStr], _SpooledTemporaryFileBase): | |
def seek(self, offset: int, whence: int = ...) -> int: ... | ||
def tell(self) -> int: ... | ||
def truncate(self, size: int | None = None) -> None: ... # type: ignore[override] | ||
def write(self, s: AnyStr) -> int: ... | ||
def writelines(self, iterable: Iterable[AnyStr]) -> None: ... # type: ignore[override] | ||
@overload | ||
def write(self: SpooledTemporaryFile[str], s: str) -> int: ... | ||
@overload | ||
def write(self: SpooledTemporaryFile[bytes], s: ReadableBuffer) -> int: ... | ||
@overload | ||
def writelines(self: SpooledTemporaryFile[str], iterable: Iterable[str]) -> None: ... | ||
@overload | ||
def writelines(self: SpooledTemporaryFile[bytes], iterable: Iterable[ReadableBuffer]) -> None: ... | ||
def __iter__(self) -> Iterator[AnyStr]: ... # type: ignore[override] | ||
# These exist at runtime only on 3.11+. | ||
def readable(self) -> bool: ... | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably don't need this
type: ignore
anymore (as well as several others), with the latest mypy release.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cleaned up all comments referencing that issue.