-
-
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
Better error message when union may not have been narrowed #17036
Better error message when union may not have been narrowed #17036
Comments
I want to fix this issue. |
I want to work on this. |
I would like to work on this with a group for a college software engineering class. |
Any of you please feel free to, just post on this issue when you have an open PR that passes tests! |
I would similarly like to work on it. |
I want to fix this |
I felt many people missed what you( @JukkaL ) meant by often None to only none. I have added hint for all the missing attribute in my pr. |
Updated messages.py to include a helpful note suggesting the use of "if s is not None" to handle cases where Union types might include None. This enhancement provides clearer guidance for users encountering attribute errors with Union types.
Feature
If some attribute is not defined for a single union item (often
None
), we could give a hint that the type may need to be narrowed down.Pitch
New users don't always figure out that they need an
isinstance
or anis not None
check, and mypy could make this easier for beginners.Toy example where this could apply:
I'm not sure what a good hint could be, but here's an initial idea:
The text was updated successfully, but these errors were encountered: