-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Strange "Attributes without a default cannot follow attributes with one" when extending a dataclass from a package #6960
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
Thanks for reporting! Hm, interesting, looks like a bug in the caching logic. Could you please try also with |
Yes, (the crash is on a different file, |
Yes, please open another issue for this. |
Done. As a side note (may or may not be helpful): I do feel that around the area of code that gives this |
This is why I proposed to try |
With mypy 0.720, which according to http://mypy-lang.org/news.html ships with the new semantic analyzer activated by default, the problem still happens to me. |
Just checked this in |
Apologies upfront, this must be the worst bug report I've ever made. I can only reproduce it every now and then, and only in a quite complicated code base. Just logging it here in case it rings a bell (or someone else has the same issue).
I have a package (which we distribute through our own, private, pypi), with type-support (
py.typed
file present). There are no stub files, all types are inline.The package defines a dataclass, e.g. file
cars.py
Now in my main program (main.py) I need to get a dataclass that is very much like a Car, I just need to be able to set the top_speed to "uknown" (a string).
Now I would expect mypy to give a warning (Subclass not compatible with super class). What happens however is this:
The first run, no errors. Subsequent runs (same command) give the errors below (until
.mypy-cache/
is removed, after which the first run again is errorfree)So what seems to happen is that mypy (incorrectly) assumes that the
top_speed
for UnknownCar will be added as last argument (and then it complains, correctly, that the argument before it, brand, has a default)The next 2 error however point to the lines where
name
andtop_speed
are defined incars.py
(even though the error saysmain.py
). If I add more newlines to the cars.py file, these line numbers in the errormessage change, and if I give default values to them, the errors disappear. By giving a fake default (ofdataclasses.field()
) to all entries, all errors disappear. Note that no amount oftype: ignore
in themain.py
file seems to be able to get rid of the errors.The behaviour was observed (however not always consistently) in mypy 0.670, 0.701 and HEAD.
The text was updated successfully, but these errors were encountered: