The problem is the same as in #708. I would however not close this as a duplicate, because this issue highlights another aspect of the problem.
Reacted by Nick Sweeting, Dentosal, Gregory Gerasev, Krzysztof Kozmic, Stevan Milic, Malcolm Greaves, Cole Geerts, Srini Muthu, Diego Garcia, Blazej Michalik and 4 more
I just came across the same issue. I guess a lot of people are going to face this issue very soon, as it's very easy to reproduce it using dataclasses.
I guess this should be not hard to fix, mypy cares whether a callable was assigned in class (to match what Python does), so we should just tweak the Vars in plugin to pretend they were assigned on self. But we still need a volunteer who will fix this.
I've found that another workaround to this is to use a callback protocol instead of Callable
Reacted by Philipp Weidenhiller, Josiah Kaviani, Pedro Cattori, Jordan Eremieff, Hong Minhee (洪 民憙), Stevan Milic, Jonathan Slenders, Kevin Conley, Maksim, Daniel Pinyol and 6 more
changed the title [-]Dataclass with function fields incorrectly thinks first argument is self[/-][+]Class with function fields incorrectly thinks first argument is self[/+]on Aug 29, 2019
Activity
ilevkivskyi commented on Aug 15, 2018
This is not something specific to dataclasses. There is a simpler repro that gives same errors:
The problem is the same as in #708. I would however not close this as a duplicate, because this issue highlights another aspect of the problem.
vim345 commented on Sep 24, 2018
I just came across the same issue. I guess a lot of people are going to face this issue very soon, as it's very easy to reproduce it using dataclasses.
ilevkivskyi commented on Sep 25, 2018
I guess this should be not hard to fix, mypy cares whether a callable was assigned in class (to match what Python does), so we should just tweak the Vars in plugin to pretend they were assigned on self. But we still need a volunteer who will fix this.
ojii commented on Nov 27, 2018
If someone needs a workaround, this works:
s-knibbs commented on Mar 27, 2019
I've found that another workaround to this is to use a callback protocol instead of Callable
no-longer-on-githu-b commented on Jul 17, 2019
When using NamedTuple instead of dataclass this problem does not arise.
TH3CHARLie commented on Jan 21, 2020
I volunteer to fix this and any guidances will be greatly helpful @ilevkivskyi
ilevkivskyi commented on Jan 22, 2020
@TH3CHARLie Fixing this in general may be tricky, but fixing just the dataclass case, should be easy. In any case, please go ahead!
No coverage on kind.py until problems due to python/mypy#5485 is ok
Squashed commit of the following:
39 remaining items
Fix callable instance variable support (python#10548)
Fix callable instance variable support (take 2) (#13400)
Type get_response with a callback protocol.
Reflect the deprecation of get_response being None. (#1086)