mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
7344374dd0
* BaseModel: Add __match_args__ attribute to namespace * changelog * amend docs * add tests * Update changes/3920-irgolic.md Co-authored-by: Samuel Colvin <samcolvin@gmail.com> * Update .github/workflows/ci.yml Co-authored-by: Samuel Colvin <samcolvin@gmail.com> * rename test_match => test_structural_pattern_matching * pytest.skip => pytest.mark.skipif * Revert "BaseModel: Add __match_args__ attribute to namespace" This reverts commit 79367356fddac90b047b10620dc895425ec25b40. * adjust tests for kwarg only structural pattern matching * adjust docs for kwarg only pattern matching * changes: Support => Document * fix docs? Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
18 lines
346 B
Python
18 lines
346 B
Python
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')
|