-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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 iterating a Tuple list of @dataclass Protocol #15618
Comments
This is a valid crash report (since mypy should never crash on syntactically valid Python code). But the quick fix is "don't do that" — it doesn't really make much sense to add |
For context I believe the original writer of this code wanted to offer an API using a Protocol but then also added features in it (the example is shortened) and ended up having some classes inheriting from the Protocol. I agree that the use case is odd (and I plan on refactoring it), but the PEP shows examples of explicitly inheriting a Protocol so it could be a "valid" usage. Thanks for the swift answer :) |
Interestingly, I can only reproduce on mypy |
Anyway, here's a smaller repro that crashes with the same traceback on the from dataclasses import dataclass
from typing import Protocol, Tuple
@dataclass
class WithValidityPeriod(Protocol): ...
periods: Tuple[WithValidityPeriod, WithValidityPeriod]
list(periods) |
I bisected to find the source of the crash:
cc. @ikonst |
We had multiple issues so it's possible that what crashed on 1.4.1 and led me to using Thanks for the simple repro bit. |
It's still a very valid crash report, and it's great to discover these things before a release! |
I'll take a look over the weekend. |
The root cause is hacky creation of incomplete symbols; instead switching to `add_method_to_class` which does the necessary housekeeping. Fixes #15618.
Crash Report
MyPy crashes when trying to validate a code bit enumerating a
List[Tuple[MyType, MyType]]
whereMyType
is a@dataclass
decoratedProtocol
(see example code below).Traceback
(Paths redacted)
To Reproduce
I used the trunk version of MyPy and ran
mypy --show-traceback mypy_test.py
using the following code snippet:Your Environment
mypy.ini
(and other config files): noneThe text was updated successfully, but these errors were encountered: