mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
19 lines
368 B
Python
19 lines
368 B
Python
# requires python3.10
|
|
from pydantic import BaseModel
|
|
|
|
|
|
class Pet(BaseModel):
|
|
name: str
|
|
species: str
|
|
|
|
|
|
a = Pet(name='Bones', species='dog')
|
|
|
|
match a:
|
|
# match `species` to 'dog', declare and initialize `dog_name`
|
|
case Pet(species='dog', name=dog_name):
|
|
print(f'{dog_name} is a dog')
|
|
# default case
|
|
case _:
|
|
print('No dog matched')
|