GenericAPIView has missing type parameters, but when added 'type' object is not subscriptable
See original GitHub issueBug report
What’s wrong
When using mypy with strict=true, it issues the following error:
Missing type parameters for generic type "GenericAPIView"
.
So, I check the type and add it, but I’m now getting a runtime error:
TypeError: 'type' object is not subscriptable
.
I am using django_stubs_ext.monkeypatch()
, which solves the problem for other similar issues.
I haven’t test it on its own, but this should suffice, as a reproducible test:
from rest_framework.generics import GenericAPIView
class ShouldWorkView(GenericAPIView[None]):
...
How is that should be
The above example should pass, with no issues.
System information
- OS: Arch
python
version: 3.10django
version: 4.0.7mypy
version: 0.942django-stubs
version: 1.12.0
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Missing type parameters for generic type "File" · Issue #1061 ...
error: Missing type parameters for generic type "File" #1061 ... TypeError: 'type' object is not subscriptable. The text was updated ...
Read more >Why isn't this function type-annotated correctly (error: Missing ...
Supply the annotation as a string. The Python interpreter (runtime) will not interpret the annotation, but mypy picks up the proper meaning.
Read more >Python TypeError: 'type' object is not subscriptable Solution
On Career Karma, learn the cause of and the solution to the common TypeError: 'type' object is not subscriptable Python error.
Read more >Machinalis: Blog
Having to add types to arguments helped me notice several unused arguments to functions that could just be removed, simplifying code for free....
Read more >python/typing - Gitter
Hi, i've made stubs for some package, and while making had not problems with types resolving, but at finish, met several problems with...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You can pass the classes you want to monkeypatch in the
extra_classes
parameter todjango_stubs_ext.monkeypatch()
.Example:
or you can manually monkeypatch them:
I believe you’re hitting this issue: https://mypy.readthedocs.io/en/latest/runtime_troubles.html#using-classes-that-are-generic-in-stubs-but-not-at-runtime. The solution suggested on that doc page worked for me.