add_method
Very closely related to mypy.plugins.common.add_method_to_class, with a few pydantic-specific changes.
def add_method(
api: SemanticAnalyzerPluginInterface | CheckerPluginInterface,
cls: ClassDef,
name: str,
args: list[Argument],
return_type: Type,
self_type: Type | None,
tvar_def: TypeVarType | None,
is_classmethod: bool
) - > None
Very closely related to mypy.plugins.common.add_method_to_class, with a few pydantic-specific changes.
Parameters
| Name | Type | Description |
|---|---|---|
| api | `SemanticAnalyzerPluginInterface | CheckerPluginInterface` |
| cls | ClassDef | The Mypy class definition object where the new method will be injected. |
| name | str | The name of the method to be created and added to the class. |
| args | list[Argument] | A list of Mypy Argument objects representing the method's parameters, excluding the initial self/cls argument. |
| return_type | Type | The Mypy type representing the return value of the generated method. |
| self_type | `Type | None` |
| tvar_def | `TypeVarType | None` |
| is_classmethod | bool | Whether the method should be treated as a class method, including the appropriate decorator and first argument type. |
Returns
| Type | Description |
|---|---|
None | Nothing; the method is added to the class definition in-place. |