Core

Fundamental utilties

callable_name


def callable_name(
    c:Callable
)->str:

Get the name of the callable c.

Exported source
def callable_name(c: Callable) -> str:
    "Get the name of the callable `c`."
    return getattr(c, '__name__', c.__class__.__name__)

This works for any function:

assert callable_name(max) == "max"

And for any classes:

class _A: pass
assert callable_name(_A) == "_A"

public_attrs


def public_attrs(
    o
):

Retrieve the public attributes of the object o.

Exported source
def public_attrs(o):
    "Retrieve the public attributes of the object `o`."
    return [a for a in dir(o) if not a.startswith('_')]

public_attrs will hide any attribute on an object if it starts with an underscore.

_A.print = print
_A._private_print = print
_A.__python_internal__ = print
assert public_attrs(_A) == ["print"]