mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
23 lines
337 B
Python
23 lines
337 B
Python
from pydantic import BaseModel
|
|
|
|
|
|
class FooBarModel(BaseModel):
|
|
a: str
|
|
b: dict
|
|
|
|
class Config:
|
|
allow_mutation = False
|
|
|
|
|
|
foobar = FooBarModel(a='hello', b={'apple': 'pear'})
|
|
|
|
try:
|
|
foobar.a = 'different'
|
|
except TypeError as e:
|
|
print(e)
|
|
|
|
print(foobar.a)
|
|
print(foobar.b)
|
|
foobar.b['apple'] = 'grape'
|
|
print(foobar.b)
|