Description
When using mypy
with --strict
, it requires you to fill in the TypeVar for whichever generic type you're using. For example:
from django.contrib import admin
from .models import Example
@admin.register(Example)
class ExampleAdmin(admin.ModelAdmin[Example]):
...
This raises: E1136: Value 'admin.ModelAdmin' is unsubscriptable (unsubscriptable-object)
.
It's not happening for all types though. For example, DRF serializers, seem to be just fine. These are the ones that are raising the error on my project: admin.ModelAdmin
, forms.ModelForm
and m.PositiveSmallIntegerField
.
To be honest, I'm not sure where this issue fits. Here? django-stubs
? pylint
? I thought this was a good place to start. If you feel otherwise, feel free to close the issue and I'll open another in somewhere more relevant.
I felt like I should open the issue as I didn't find a single instance of someone having the exact same problem.
See also:
pylint-dev/pylint#3882
I'm using the latest version for Django (and respective stubs), DRF (and respective stubs), pylint, mypy and pylint-django.
And thank you!