mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 14:50:19 +00:00
0af5e5f559
* Allow generics to extend concrete classes. fixes #2005 * Update the docs * Updote the changes * Convert double quotes to single quotes * Fix formatting * Add a check for data * Update example * Add a skip_36 decorator that got accidentally deleted when resolving conflicts.
20 lines
386 B
Python
20 lines
386 B
Python
from typing import TypeVar, Generic
|
|
from pydantic.generics import GenericModel
|
|
|
|
TypeX = TypeVar('TypeX')
|
|
TypeY = TypeVar('TypeY')
|
|
TypeZ = TypeVar('TypeZ')
|
|
|
|
|
|
class BaseClass(GenericModel, Generic[TypeX, TypeY]):
|
|
x: TypeX
|
|
y: TypeY
|
|
|
|
|
|
class ChildClass(BaseClass[int, TypeY], Generic[TypeY, TypeZ]):
|
|
z: TypeZ
|
|
|
|
|
|
# Replace TypeY by str
|
|
print(ChildClass[str, int](x=1, y='y', z=3))
|