Configures the BaseModel subclass according to the plugin settings. In particular: * determines the model config and fields, * adds a fields-aware signature for the initializer and construct methods * freezes the class if allow_mutation = False or frozen = T
(self)
| 299 | self.plugin_config = plugin_config |
| 300 | |
| 301 | def transform(self) -> None: |
| 302 | """ |
| 303 | Configures the BaseModel subclass according to the plugin settings. |
| 304 | |
| 305 | In particular: |
| 306 | * determines the model config and fields, |
| 307 | * adds a fields-aware signature for the initializer and construct methods |
| 308 | * freezes the class if allow_mutation = False or frozen = True |
| 309 | * stores the fields, config, and if the class is settings in the mypy metadata for access by subclasses |
| 310 | """ |
| 311 | ctx = self._ctx |
| 312 | info = ctx.cls.info |
| 313 | |
| 314 | self.adjust_validator_signatures() |
| 315 | config = self.collect_config() |
| 316 | fields = self.collect_fields(config) |
| 317 | is_settings = any(get_fullname(base) == BASESETTINGS_FULLNAME for base in info.mro[:-1]) |
| 318 | self.add_initializer(fields, config, is_settings) |
| 319 | self.add_construct_method(fields) |
| 320 | self.set_frozen(fields, frozen=config.allow_mutation is False or config.frozen is True) |
| 321 | info.metadata[METADATA_KEY] = { |
| 322 | 'fields': {field.name: field.serialize() for field in fields}, |
| 323 | 'config': config.set_values_dict(), |
| 324 | } |
| 325 | |
| 326 | def adjust_validator_signatures(self) -> None: |
| 327 | """When we decorate a function `f` with `pydantic.validator(...), mypy sees |
no test coverage detected