-
-
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
Crash when overriding partially typed attribute with partially typed property #11686
Comments
This small change fixes the crash. But, I am not sure it is correct: Maybe you will be interested in creating a PR? You can add your case somewhere here: https://github.com/python/mypy/blob/master/test-data/unit/check-classes.test |
Thanks for the response! This change seems to solve this crash, but I'm not 100% it's not treating a symptom and not the cause - the inferred type of If I remove all the I'd be happy to make a PR, but in this case I don't think I understand the underlying cause myself yet - if your solution is correct, I don't fully understand why - so I'd rather wait on that. I can try and have a look myself, to try and satisfy myself that I understand the solution completely, but it may take me a while. |
This transpires to be more general than just class Base:
def __init__(self, arg: int):
self.partial_type = []
self.force_deferral = []
force_deferral = []
class Derived(Base):
def partial_type(self) -> int:
... The I think the correct solution to this is what's given above in #11686 (comment), since I now understand why the seemingly unrelated |
Attributes can still be partially typed (e.g. `<partial list[?]>`) after a parent-class definition if the block they are declared in is deferred. The first pass for child classes might then encounter this type when considering method overrides, which could cause a crash when attempting to determine subtype compatibility. Fixes #11686 Fixes #11981
Attributes can still be partially typed (e.g. `<partial list[?]>`) after a parent-class definition if the block they are declared in is deferred. The first pass for child classes might then encounter this type when considering method overrides, which could cause a crash when attempting to determine subtype compatibility. Fixes python#11686 Fixes python#11981
Crash Report
I've been seeing
mypy
crashes with the released 0.910 and the current state of the dev branch. It appears to occur when a child class overrides a partially type instance attribute in its parent with a property that's also partially typed, but it also seems to matter that there's a second property in the parent that has at least a setter method.I've cut it down as far as I could to the reproducer below the traceback.
Traceback
To Reproduce
The traceback above was generated by the file
partial_list.py
:This was run with
mypy --show-traceback partial_list.py
in an empty venv, after deleting the.mypy-cache
directory, and I don't think there's any other configuration being pulled from anywhere.This was as small a reproducer as I could find. It seems to matter that there are two properties (although one of them only needs a setter), and the child class seems to need to be overriding a partially typed instance variable with a getter property that's also partially typed.
Your Environment
--show-traceback
mypy.ini
(and other config files): noneThe text was updated successfully, but these errors were encountered: