Uh oh!
There was an error while loading. Please reload this page.
Extend the dataclass plugin to deal with callable properties - #10292
Conversation
At runtime, the callable properties of dataclasses are handled in the way one would expect: they are not passed a `self` argument. Mypy, however, just sees them as callable class attributes and generates errors about missing arguments. This is a special case of what is discussed in python#708. I donʼt have a general solution for that problem, but for dataclasses, I can fix it by automatically converting the callable entries in a data class into (settable) properties. That makes them work properly via-a-vis the typechecker.
this is (hopefully) temporary until python/mypy#10292 is merged
this is (hopefully) temporary until python/mypy#10292 is merged
aecay
commented
Apr 8, 2021
The travis failure is in the python3.5 unit test job, which fails before the tests even run: This same job passed on fb07856, and I can't see where the changes in 6149640 would have caused it to start failing... So it looks like a transient issue. When I try to rerun the job on Travis, I get an error ("could not rerun job") -- maybe a permissions issue? In any case, I figured it makes sense to wait for reviews and maybe a little help coaxing the CI to rerun rather than keep bashing away at it for the moment. |
JelleZijlstra
commented
Apr 8, 2021
I used the powers vested in me to click the "Re-run job button" in Travis. For future reference, closing and reopening the PR tends to work too. |
JukkaL
left a comment
There was a problem hiding this comment.
Thanks for the PR! Looks good.
Description
At runtime, the callable properties of dataclasses are handled in the
way one would expect: they are not passed a
selfargument. Mypy,however, just sees them as callable class attributes and generates
errors about missing arguments. This is a special case of what is
discussed in #708. I donʼt have a general solution for that problem,
but for dataclasses, I can fix it by automatically converting the
callable entries in a data class into (settable) properties. That makes
them work properly via-a-vis the typechecker.
(Explain how this PR changes mypy.)
Test Plan
Added unit tests which verify: