Opened 2 years ago

Closed 2 years ago

#33558 closed Bug (duplicate)

Abstract model inheriting from typing.Generic[T] causes TypeError

Reported by: Rob Percival Owned by: nobody
Component: Database layer (models, ORM) Version: 4.0
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The exception message is "TypeError: Cannot inherit from plain Generic". Example:

T = typing.TypeVar("T")

class AbstractModel(models.Model, Generic[T]):
    foo: T  # Bad example of how you might use a TypeVar

    class Meta:
        abstract = True

class IntModel(AbstractModel[int]):
    …

A better explanation of the issue and a patch can be found here: https://github.com/typeddjango/django-stubs/issues/299

Change History (1)

comment:1 by Mariusz Felisiak, 2 years ago

Resolution: duplicate
Status: newclosed

Duplicate #33174.

Note: See TracTickets for help on using tickets.
Back to Top