Skip to content

Mypy and unsubscriptable-object #361

Open
@XF-FW

Description

@XF-FW

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions