Skip to main content

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

NameTypeDescription
api`SemanticAnalyzerPluginInterfaceCheckerPluginInterface`
clsClassDefThe Mypy class definition object where the new method will be injected.
namestrThe name of the method to be created and added to the class.
argslist[Argument]A list of Mypy Argument objects representing the method's parameters, excluding the initial self/cls argument.
return_typeTypeThe Mypy type representing the return value of the generated method.
self_type`TypeNone`
tvar_def`TypeVarTypeNone`
is_classmethodboolWhether the method should be treated as a class method, including the appropriate decorator and first argument type.

Returns

TypeDescription
NoneNothing; the method is added to the class definition in-place.