Type mismatch in email.charset.Charset.body_encode
#10429
Labels
stubs: false positive
Type checkers report false errors
Summary
Modification Target:
Charset.body_encode
instdlib/email/charset.pyi
Current type hint:
(self, string: str) -> str
Proposed type hint:
(self, string: Optional[str]) -> Optional[str]
See the existing implementation here: charset.pyi#L21
Description
The method
Charset.body_encode
can returnNone
if it's invoked withNone
as thestring
parameter.Although the type hint currently does not allow for
None
to be passed as an argument, there's a mismatch with how it's used in theMessage.set_charset
method from the standard library'semail/message.py
, which can passNone
tobody_encode
. This is because theMessage
class's attributeself._payload
is initially set toNone
.The mismatch (passing
None
as an argument) was discovered in the CPython email unit test,TestMessageAPI.test_getset_charset
, found intest/test_email/test_email.py
. The minimized example below demonstrates the type mismatch:P.S. All CPython links refer to commit hash
0481b8...
from the current CPython 3.12 branch.The text was updated successfully, but these errors were encountered: