mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
4af50043f1
* Print name classes * use `repr` to display class name Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
18 lines
416 B
Python
18 lines
416 B
Python
from typing import Generic, TypeVar, Type, Any, Tuple
|
|
|
|
from pydantic.generics import GenericModel
|
|
|
|
DataT = TypeVar('DataT')
|
|
|
|
|
|
class Response(GenericModel, Generic[DataT]):
|
|
data: DataT
|
|
|
|
@classmethod
|
|
def __concrete_name__(cls: Type[Any], params: Tuple[Type[Any], ...]) -> str:
|
|
return f'{params[0].__name__.title()}Response'
|
|
|
|
|
|
print(repr(Response[int](data=1)))
|
|
print(repr(Response[str](data='a')))
|