Skip to content

Method

Method

Method(method, cls, skip_self: bool = True)

Bases: Function

The Method class represents a method of a class.

Parameters:

Name Type Description Default
method Callable

The method to be inspected.

required
cls type

The class to which the method belongs.

required
skip_self bool

Whether to skip the self parameter.

True

Attributes:

Name Type Description
name str

The name of the method.

docstring str

The docstring of the method.

has_docstring bool

Whether the method has a docstring.

description str

The description part of the method's docstring.

params list[Parameter]

A list of parameters of the method.

dict dict

A dictionary representation of the method's attributes.

is_static bool

Whether the method is static.

is_classmethod bool

Whether the method is a classmethod.

is_property bool

Whether the method is a property.

is_private bool

Whether the method is private.

is_protected bool

Whether the method is protected.

is_public bool

Whether the method is public.

is_inherited bool

Whether the method is inherited.

Source code in objinspect/method.py
def __init__(self, method, cls, skip_self: bool = True):
    super().__init__(method, skip_self)
    self.cls = cls

split_args_kwargs

split_args_kwargs(func_args: dict, func: Function | Method) -> tuple[tuple, dict]

Split the arguments passed to a function into positional and keyword arguments.

Source code in objinspect/method.py
def split_args_kwargs(func_args: dict, func: Function | Method) -> tuple[tuple, dict]:
    """Split the arguments passed to a function into positional and keyword arguments."""
    args, kwargs = [], {}
    for param in func.params:
        if param.kind == _ParameterKind.POSITIONAL_ONLY:
            args.append(func_args[param.name])
        else:
            kwargs[param.name] = func_args[param.name]
    return tuple(args), kwargs