You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from django.utils.decorators import classonlymethod
class Foo:
@classonlymethod
def bar(cls):
pass
Error from mypy:
error: Argument 1 to "classonlymethod" has
incompatible type "Callable[[Foo], Any]"; expected "Callable[[Any, VarArg(Any), KwArg(Any)], Any]" [arg-type]
What's wrong
Error occurred, but it seems to be more related to mypy itself. The problem is described here
I created this issue here, because I think the solution is very easy to fix it and what I understood from here there will not change how mypy treats subclasses of classmethod
Problem stub: django-stubs/utils/decorators.pyi
class classonlymethod(classmethod): ...
How is that should be
Changing to alias solves the error
classonlymethod = classmethod
Let me know what do you think
System information
OS:
python version: 3.9.16
django version: 3.2.18
mypy version: 1.2.0
django-stubs version: 4.2.0
django-stubs-ext version: 4.2.0
The text was updated successfully, but these errors were encountered:
I've experienced this issue myself as well. I'm using # type: ignore[arg-type] right now.
I agree that aliasing the types (classonlymethod = classmethod) should fix it. The downside is that type checkers won't know that classonlymethod methods aren't accessible on instances. But that's already the case right now.
Not sure if there could be other downsides?
Ideally this would be solved by adding mypy plugin logic, to teach mypy about instance behavior. But not a high priority IMO.
Bug report
Error from mypy:
What's wrong
Error occurred, but it seems to be more related to mypy itself. The problem is described here
I created this issue here, because I think the solution is very easy to fix it and what I understood from here there will not change how mypy treats subclasses of
classmethod
Problem stub:
django-stubs/utils/decorators.pyi
How is that should be
Changing to alias solves the error
Let me know what do you think
System information
python
version: 3.9.16django
version: 3.2.18mypy
version: 1.2.0django-stubs
version: 4.2.0django-stubs-ext
version: 4.2.0The text was updated successfully, but these errors were encountered: