Adds a new method to a class definition.
(
api: SemanticAnalyzerPluginInterface | CheckerPluginInterface,
cls: ClassDef,
name: str,
# MethodSpec items kept for backward compatibility:
args: list[Argument],
return_type: Type,
self_type: Type | None = None,
tvar_def: list[TypeVarType] | TypeVarType | None = None,
is_classmethod: bool = False,
is_staticmethod: bool = False,
)
| 223 | |
| 224 | |
| 225 | def add_method_to_class( |
| 226 | api: SemanticAnalyzerPluginInterface | CheckerPluginInterface, |
| 227 | cls: ClassDef, |
| 228 | name: str, |
| 229 | # MethodSpec items kept for backward compatibility: |
| 230 | args: list[Argument], |
| 231 | return_type: Type, |
| 232 | self_type: Type | None = None, |
| 233 | tvar_def: list[TypeVarType] | TypeVarType | None = None, |
| 234 | is_classmethod: bool = False, |
| 235 | is_staticmethod: bool = False, |
| 236 | ) -> FuncDef | Decorator: |
| 237 | """Adds a new method to a class definition.""" |
| 238 | _prepare_class_namespace(cls, name) |
| 239 | |
| 240 | if tvar_def is not None and not isinstance(tvar_def, list): |
| 241 | tvar_def = [tvar_def] |
| 242 | |
| 243 | func, sym = _add_method_by_spec( |
| 244 | api, |
| 245 | cls.info, |
| 246 | name, |
| 247 | MethodSpec(args=args, return_type=return_type, self_type=self_type, tvar_defs=tvar_def), |
| 248 | is_classmethod=is_classmethod, |
| 249 | is_staticmethod=is_staticmethod, |
| 250 | ) |
| 251 | cls.info.names[name] = sym |
| 252 | cls.info.defn.defs.body.append(func) |
| 253 | return func |
| 254 | |
| 255 | |
| 256 | def add_overloaded_method_to_class( |
no test coverage detected
searching dependent graphs…