-
-
Notifications
You must be signed in to change notification settings - Fork 2.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
"Message | str | Any" has no attribute "get_param" #17034
Comments
I think For the case when If you adjust your code to print the types: from email import message_from_bytes
msg = message_from_bytes(b"bla")
reveal_type(msg)
if not msg.is_multipart():
raise
reveal_type(msg)
for part in msg.get_payload():
reveal_type(part)
print(part.get_param("name")) Then run it on 1.8.0:
1.9.0:
I think 1.8.0 saying |
Thanks for the reply. |
@yellowhat I'm not really familiar with this library, but it seems to me that you're confident that from email import message_from_bytes
from email.message import Message
msg = message_from_bytes(b"bla")
if not msg.is_multipart():
raise
for part in msg.get_payload():
assert isinstance(part, Message)
print(part.get_param("name")) This will ensure the type is correct by exploding at runtime if it is wrong (as in our example, come to think of it). You could also write similar code to check the type and do something appropriate in each case. ( For more information, see https://mypy.readthedocs.io/en/stable/type_narrowing.html , https://docs.python.org/3/library/functions.html#isinstance , https://docs.python.org/3/reference/simple_stmts.html#assert |
Thanks for the suggestion. But if I have to add code to workaround this, I would just ignore it: part.get_param("name") # type: ignore[union-attr] |
Bug Report
Hi,
consider the following example code.
It was ok up to mypy 1.8.0, it does not work anymore with 1.9.0.
Thanks
To Reproduce
Expected Behavior
Actual Behavior
Your Environment
--install-types --non-interactive --strict
mypy.ini
(and other config files):The text was updated successfully, but these errors were encountered: