-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Type mismatch in email.charset.Charset.get_body_encoding
#10430
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
Comments
This comment was marked as outdated.
This comment was marked as outdated.
Thanks for your contribution, but I disagree with the classification of these as duplicated issues. While #10429 and #10430 might seem similar in structure, they target different methods and the reasons for the type mismatches are not identical. Therefore, in my view, these should be regarded as distinct issues. much like how issues 8615 and 8616 were jointly addressed in pull request 8617. If the preference is still to collect similar proposals in one issue, may I suggest moving the issue report from #10430 to #10429? |
My apologies, that serves me right for trying to triage issues before having my coffee :( |
Thanks! Normally we try to avoid union return types and prefer to use |
Uh oh!
There was an error while loading. Please reload this page.
Summary
Modification Target:
Charset.get_body_encoding
instdlib/email/charset.pyi
Current type hint:
(self) -> str
Proposed type hint:
(self) -> str | Callable[[Message], None]
See the existing implementation here: charset.pyi#L17
Description
The method
Charset.get_body_encoding
can return a functionencode_7or8bit
if it reaches final else-branch case.Using the type hint for
encode_7or8bit
, the return type hint forget_body_encoding
should bestr | Callable[[Message], None
.typeshed/stdlib/email/encoders.pyi
Line 7 in 81b8211
I found this mismatch in the CPython email unit test,
TestMiscellaneous.test_get_body_encoding_with_uppercase_charset
, found intest/test_email/test_email.py
. The minimized example below shows type mismatch at runtime, where the callcharset.get_body_encoding()
at the last statement returnsencode_7or8bit
function: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: