Marks all fields as properties so that attempts to set them trigger mypy errors. This is the same approach used by the attrs and dataclasses plugins.
(self, fields: list[PydanticModelField], api: SemanticAnalyzerPluginInterface, frozen: bool)
| 979 | ) |
| 980 | |
| 981 | def set_frozen(self, fields: list[PydanticModelField], api: SemanticAnalyzerPluginInterface, frozen: bool) -> None: |
| 982 | """Marks all fields as properties so that attempts to set them trigger mypy errors. |
| 983 | |
| 984 | This is the same approach used by the attrs and dataclasses plugins. |
| 985 | """ |
| 986 | info = self._cls.info |
| 987 | for field in fields: |
| 988 | sym_node = info.names.get(field.name) |
| 989 | if sym_node is not None: |
| 990 | var = sym_node.node |
| 991 | if isinstance(var, Var): |
| 992 | var.is_property = frozen or field.is_frozen |
| 993 | elif isinstance(var, PlaceholderNode) and not self._api.final_iteration: |
| 994 | # See https://github.com/pydantic/pydantic/issues/5191 to hit this branch for test coverage |
| 995 | self._api.defer() |
| 996 | # `var` can also be a FuncDef or Decorator node (e.g. when overriding a field with a function or property). |
| 997 | # In that case, we don't want to do anything. Mypy will already raise an error that a field was not properly |
| 998 | # overridden. |
| 999 | else: |
| 1000 | var = field.to_var(info, api, use_alias=False) |
| 1001 | var.info = info |
| 1002 | var.is_property = frozen |
| 1003 | var._fullname = info.fullname + '.' + var.name |
| 1004 | info.names[var.name] = SymbolTableNode(MDEF, var) |
| 1005 | |
| 1006 | def get_config_update(self, name: str, arg: Expression, lax_extra: bool = False) -> ModelConfigData | None: |
| 1007 | """Determines the config update due to a single kwarg in the ConfigDict definition. |