mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
679e5d149e
* doc: add an example of inheritance with Generics * Update the changes directory with the doc changes.
15 lines
314 B
Python
15 lines
314 B
Python
from typing import TypeVar, Generic
|
|
from pydantic.generics import GenericModel
|
|
|
|
TypeX = TypeVar('TypeX')
|
|
|
|
class BaseClass(GenericModel, Generic[TypeX]):
|
|
X: TypeX
|
|
|
|
class ChildClass(BaseClass[TypeX], Generic[TypeX]):
|
|
# Inherit from Generic[TypeX]
|
|
pass
|
|
|
|
# Replace TypeX by int
|
|
print(ChildClass[int](X=1))
|