mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
e7227db41a
* starting insert prints * working exec_script * remove prints, fix exec_examples.py * more cleanup of examples, better model printing * upgrade netlify runtime * extra docs deps * few more small tweaks
22 lines
407 B
Python
22 lines
407 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)
|
|
# > "FooBarModel" is immutable and does not support item assignment
|
|
|
|
print(foobar.a)
|
|
print(foobar.b)
|
|
foobar.b['apple'] = 'grape'
|
|
print(foobar.b)
|