Adds a fields-aware `__init__` method to the class. The added `__init__` will be annotated with types vs. all `Any` depending on the plugin settings.
(self, fields: List['PydanticModelField'], config: 'ModelConfigData', is_settings: bool)
| 457 | return all_fields |
| 458 | |
| 459 | def add_initializer(self, fields: List['PydanticModelField'], config: 'ModelConfigData', is_settings: bool) -> None: |
| 460 | """ |
| 461 | Adds a fields-aware `__init__` method to the class. |
| 462 | |
| 463 | The added `__init__` will be annotated with types vs. all `Any` depending on the plugin settings. |
| 464 | """ |
| 465 | ctx = self._ctx |
| 466 | typed = self.plugin_config.init_typed |
| 467 | use_alias = config.allow_population_by_field_name is not True |
| 468 | force_all_optional = is_settings or bool( |
| 469 | config.has_alias_generator and not config.allow_population_by_field_name |
| 470 | ) |
| 471 | init_arguments = self.get_field_arguments( |
| 472 | fields, typed=typed, force_all_optional=force_all_optional, use_alias=use_alias |
| 473 | ) |
| 474 | if not self.should_init_forbid_extra(fields, config): |
| 475 | var = Var('kwargs') |
| 476 | init_arguments.append(Argument(var, AnyType(TypeOfAny.explicit), None, ARG_STAR2)) |
| 477 | |
| 478 | if '__init__' not in ctx.cls.info.names: |
| 479 | add_method(ctx, '__init__', init_arguments, NoneType()) |
| 480 | |
| 481 | def add_construct_method(self, fields: List['PydanticModelField']) -> None: |
| 482 | """ |
no test coverage detected