1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
import typing
from django.db import models
T = typing.TypeVar("T")
class GenericModel(typing.Generic[T], models.Model):
"""A model inheriting from typing.Generic."""
class GenericModelPEP695[T](models.Model):
"""A model inheriting from typing.Generic via the PEP 695 syntax."""
# Example from Python docs:
# https://typing.python.org/en/latest/spec/generics.html#arbitrary-generic-types-as-base-classes
T1 = typing.TypeVar("T1")
T2 = typing.TypeVar("T2")
T3 = typing.TypeVar("T3")
class Parent1(typing.Generic[T1, T2]):
pass
class Parent2(typing.Generic[T1, T2]):
pass
class Child(Parent1[T1, T3], Parent2[T2, T3]):
pass
class CustomGenericModel(Child[T1, T3, T2], models.Model):
"""A model inheriting from a custom subclass of typing.Generic."""
|