Closed Myselfito closed 7 months ago
Makes sense. Also it seems the methods
attribute doesn't actually exist.
@intgr I can work on this issue, please assign it to me.
@Sakhi29 Sorry, your comment got lost among all notifications I'm receiving. I've assigned you. In the future, there's no need to wait for assigment, just fire a PR 😄
up
Bug report
What's wrong
mypy doesn't recognize the
__name__
attribute of an action. See minimal example with error below:How is that should be
The above snippet should not raise an error. In order to achieve this we can add the
__name__
attribute to the ViewSetAction. The actions are all methods so the__name__
attribute is always defined. See also below for the use case.Use case
When checking actions in viewset methods, we could use
self.action == self.__class__.example_action.__name__
instead ofself.action == "example_action"
to limit the potential risk of action naming update (type checkers would detect the attribute error) and avoid the use of error-prone strings.System information
OS
: Windowspython
version: 3.10django
version: 4.1mypy
version: 1.4.1django-stubs
version: 4.2.3