Skip to content

Instantly share code, notes, and snippets.

@Kludex
Created September 13, 2023 09:10
Show Gist options
  • Save Kludex/2755fc739dc24718aefc739519051197 to your computer and use it in GitHub Desktop.
Save Kludex/2755fc739dc24718aefc739519051197 to your computer and use it in GitHub Desktop.
How to disable `model_` as protected namespace globally in Pydantic
from pydantic import BaseModel
BaseModel.model_config['protected_namespaces'] = ()
class Potato(BaseModel):
model_potato: str
class Carrot(BaseModel):
model_carrot: str
print(Potato(model_potato='potato'))
print(Carrot(model_carrot='carrot'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment