MCPcopy
hub / github.com/pydantic/pydantic / ModelConfigData

Class ModelConfigData

pydantic/mypy.py:1208–1248  ·  view source on GitHub ↗

Pydantic mypy plugin model config class.

Source from the content-addressed store, hash-verified

1206
1207
1208class ModelConfigData:
1209 """Pydantic mypy plugin model config class."""
1210
1211 def __init__(
1212 self,
1213 forbid_extra: bool | None = None,
1214 frozen: bool | None = None,
1215 from_attributes: bool | None = None,
1216 populate_by_name: bool | None = None,
1217 validate_by_alias: bool | None = None,
1218 validate_by_name: bool | None = None,
1219 has_alias_generator: bool | None = None,
1220 strict: bool | None = None,
1221 ):
1222 self.forbid_extra = forbid_extra
1223 self.frozen = frozen
1224 self.from_attributes = from_attributes
1225 self.populate_by_name = populate_by_name
1226 self.validate_by_alias = validate_by_alias
1227 self.validate_by_name = validate_by_name
1228 self.has_alias_generator = has_alias_generator
1229 self.strict = strict
1230
1231 def get_values_dict(self) -> dict[str, Any]:
1232 """Returns a dict of Pydantic model config names to their values.
1233
1234 It includes the config if config value is not `None`.
1235 """
1236 return {k: v for k, v in self.__dict__.items() if v is not None}
1237
1238 def update(self, config: ModelConfigData | None) -> None:
1239 """Update Pydantic model config values."""
1240 if config is None:
1241 return
1242 for k, v in config.get_values_dict().items():
1243 setattr(self, k, v)
1244
1245 def setdefault(self, key: str, value: Any) -> None:
1246 """Set default value for Pydantic model config if config value is `None`."""
1247 if getattr(self, key) is None:
1248 setattr(self, key, value)
1249
1250
1251def is_root_model(info: TypeInfo) -> bool:

Callers 2

collect_configMethod · 0.70
get_config_updateMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected