-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
AttributeError: 'UnionType' object has no attribute 'type' #3468
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
Can you come up with a repro that doesn't still depend on the pyspark stubs? I get an error on the import line. |
Let me try to dig deeper into this over the weekend. It doesn't appear in isolation, so it guess the problem can be somewhere completely else, and just manifests in an awkward way. |
Here is a simple repro for the crash: class X:
def __mod__(self, other: Union[X, str]) -> X: ...
def __rmod__(self, other: Union[X, str]) -> X: ... I think the problem is because of an unsafe cast here https://github.com/python/mypy/blob/master/mypy/checker.py#L805 |
Ah, casts! They cause so much trouble and are so misunderstood. That one should have been an assert, but how to prevent crashing? (PS Crash >= Bug so I removed the bug label.) |
TBH I am not sure what to do here. It looks like this crash happens only if |
I can have a look at this. The relevant code is really old and seems to have bit rotted (assuming that it ever worked). |
I think it is related to the issue I have described in #3227 |
I get the same error when I run mypy on
However if I run the same command but within my home directory I do not have this issue. I made sure to delete all instances of |
I can't reproduce this, but there's a slim chance that #4017 will avoid the crash. |
@ilevkivskyi in your repro (with the additional
I'm not sure if that's correct, but at least it's not a crash. |
I just created a new env and then the errors went away. Not sure what why. I had deleted all instances of |
@elazarg I am not sure this is correct behaviour, IIUC this error is intended for cases where an argument is a superclass (because of some Python logic that binary methods are called on the most derived class), therefore it should probably only apply to |
The invalid cast I mentioned moved to another line https://github.com/python/mypy/blob/master/mypy/checker.py#L925 |
Link to the invalid cast that will not go out of date if the content of checker.py changes: Line 925 in 46ecea5
|
I'm not sure the specific invalid cast is the important thing - either #4017 solve it (in which case I believe it should be merged), or the problem is not the cast itself. |
Increased priority as the crash has been reported multiple times. |
* Remove old comments, clean bail-out logic * Use fallback to find Instance when possible * Remove cast; move formatting logic to messages.py * Remove unused method * Rename variables to match check_overlapping_op_methods terminology * Remove many unused imports Potential fix to #3468, or at least avoids the crash (since it removes the unsafe cast).
#4017 hopefully fixed this. Let's reopen if this continues to be a problem. |
* Remove old comments, clean bail-out logic * Use fallback to find Instance when possible * Remove cast; move formatting logic to messages.py * Remove unused method * Rename variables to match check_overlapping_op_methods terminology * Remove many unused imports Potential fix to python#3468, or at least avoids the crash (since it removes the unsafe cast).
This looks like a regression (?) between Mypy 0.501 and 0.510.
Failure is reported at this line: https://github.com/zero323/pyspark-stubs/blob/d25da4d051f878d358bdef6a0e08a6597afbee4f/third_party/3/pyspark/sql/functions.pyi#L24 but it can be reproduced with simplified input:
Python version:
Mypy version: 0.510, 0.511
Traceback:
The text was updated successfully, but these errors were encountered: