Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/alex-ber/AlexBerUtils/llms.txt

Use this file to discover all available pages before exploring further.

The inspects module extends Python’s inspect module with utilities for method detection, argument mapping, and runtime modification of function default values.

issetdescriptor

Returns True if the object is a method descriptor that exposes a setter (has a __set__ attribute), but is not a class, method, or function.
from alexber.utils.inspects import issetdescriptor

class MyDescriptor:
    def __set__(self, obj, value):
        pass

issetdescriptor(MyDescriptor())  # True
issetdescriptor(lambda: None)    # False
object
any
required
The object to inspect.
Returns: bool

ismethod

Checks whether the given object is a bound method. Differs from inspect.ismethod in that it also returns True for functions that carry a __self__ attribute (e.g. methods accessed through certain descriptors).
from alexber.utils.inspects import ismethod

class MyClass:
    def my_method(self):
        pass

obj = MyClass()
ismethod(obj.my_method)  # True
ismethod(MyClass)        # False  (class, not method)
ismethod(lambda: None)   # False  (plain function)
object
any
required
The object to check.
Returns: boolTrue if the object is a bound method.

has_method

Checks whether a class (or any class in its MRO) defines a callable attribute with the given name.
from alexber.utils.inspects import has_method

has_method(list, 'append')   # True
has_method(list, 'nonexistent')  # False
cls
type
required
The class to inspect.
methodName
str
required
Name of the method to look for.
Returns: boolTrue if cls (or one of its base classes) has a routine with the given name.

resolve_function_args

Resolves the complete set of arguments for a function call, merging explicit positional/keyword arguments with the function’s default values.
from alexber.utils.inspects import resolve_function_args

def greet(name, greeting='Hello'):
    return f'{greeting}, {name}!'

# Explicit args only
resolve_function_args(greet, 'Alice')
# {'name': 'Alice', 'greeting': 'Hello'}

# Override a default
resolve_function_args(greet, 'Bob', greeting='Hi')
# {'name': 'Bob', 'greeting': 'Hi'}
func
Callable
required
The function whose argument mapping is to be resolved.
*args
any
Positional arguments as they would be passed to func.
**kwargs
any
Keyword arguments as they would be passed to func.
Returns: Dict[str, Any] — mapping of parameter names to their resolved values (explicit arguments take precedence over defaults).

update_function_defaults

Decorator that modifies or removes default parameter values of a function at call time.
from alexber.utils.inspects import update_function_defaults

def connect(host='localhost', port=5432, timeout=30):
    ...

# Change the default port and remove the default timeout
decorated = update_function_defaults(
    connect,
    new_defaults={'port': 6543},
    remove_defaults=['timeout'],
)

# Now 'timeout' has no default — callers must supply it
decorated(timeout=10)  # host='localhost', port=6543, timeout=10
func
Callable
required
The function or method to decorate.
new_defaults
Dict[str, Any]
Mapping of parameter names to their new default values. Defaults to {}.
remove_defaults
List[str]
List of parameter names whose default values should be removed, making them required. Defaults to [].
is_forced
bool
If False (default), only parameters that already have a default value are updated. If True, all parameters listed in new_defaults or remove_defaults are updated regardless of whether they originally had defaults.
Returns: A new callable (wrapper function) with the modified signature. The original function’s __name__, __doc__, and other attributes are preserved via functools.wraps.