-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Add containing union and offending type information when reporting on missing attributes for unions #3402
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
Conversation
Thanks for the PR! Just a small comment: I think the situation with |
cd1400e
to
0ac3f21
Compare
I used the |
Thanks for the PR! Looks pretty good. A few quick comments:
|
@JukkaL I addressed your first two points. Regarding magic methods, at least the ones you mentioned result in specialized errors. Doing
And doing
It would be desirable for these cases to also result in more specific errors (e.g., |
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 PR is almost there! I'd like to just see one docstring tweak.
@@ -361,72 +361,79 @@ def format_distinctly(self, type1: Type, type2: Type) -> Tuple[str, str]: | |||
# get some information as arguments, and they build an error message based | |||
# on them. | |||
|
|||
def has_no_attr(self, typ: Type, member: str, context: Context) -> Type: | |||
def has_no_attr(self, original_type: Type, typ: Type, member: str, context: Context) -> Type: |
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.
Document original_type
in the docstring.
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.
Looks good to me!
This is an attempt to address #2561.
For example, for the following code:
The previous error was:
With this PR, the error is:
Upade: I locally fixed the following
None
issue in the latest commit.When dealing with
None
,mypy
reportsobject
. For the example in the above issue:The previous error was:
With this PR, the error becomes:
I guess this happens because
mypy
searches up the inhertiance tree forNoneType
and I'm not sure if there's a way to get the correct type in the code - suggestions welcome.