-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
email: improve bytes handling #9032
Conversation
This comment has been minimized.
This comment has been minimized.
stdlib/email/base64mime.pyi
Outdated
def decode(string: str | bytes) -> bytes: ... | ||
from _typeshed import ReadableBuffer | ||
|
||
def header_length(bytearray: bytes | bytearray) -> int: ... |
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.
str
would work as well, and since header_encode()
explicitly checks for str
, I think it's safer to allow it here as well. In fact, the tests use str
:
def header_length(bytearray: bytes | bytearray) -> int: ... | |
def header_length(bytearray: str | bytes | bytearray) -> int: ... |
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.
My thinking was that this function is about counting bytes using len()
, and that doesn't make sense for str
because a character can be multiple bytes. I guess it works for ASCII strings, though.
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.
At first I was not going to comment this for that reason, but seeing the test using str
tipped me to comment on this.
@@ -12,7 +12,7 @@ __all__ = ["Message", "EmailMessage"] | |||
|
|||
_T = TypeVar("_T") | |||
|
|||
_PayloadType: TypeAlias = list[Message] | str | bytes | |||
_PayloadType: TypeAlias = list[Message] | str | bytes | bytearray |
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.
This change means that get_payload()
can suddenly return bytearray
, which contradicts the documentation. set_payload()
is accepting a bytearray
, though (and converting it to a str
).
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.
get_payload()
returns Any in our stub, _PayloadType
is only mentioned in a comment. I think the comment is still close enough, we can revisit it if we ever change the Any.
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.
For some reason I totally missed the comment in front of the return type ...
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
No description provided.