Misc. functions

introspection.get_parameters(callable_)

Returns a list of parameters accepted by callable_.

Parameters

callable_ (Callable) – The callable whose parameters to retrieve

Returns

A list of Parameter instances

Return type

List[Parameter]

introspection.common_ancestor(classes)

Finds the closest common parent class of the given classes. If called with an empty iterable, object is returned.

Parameters

classes – An iterable of classes

Returns

The given classes’ shared parent class

introspection.create_class(name, bases=(), attrs={}, metaclass=None, **kwargs)

Creates a new class. This is similar to types.new_class(), except it calls resolve_bases() even in python versions <= 3.7. (And it has a different interface.)

Parameters
  • name – The name of the new class

  • bases – An iterable of bases classes

  • attrs – A dict of class attributes

  • metaclass – The metaclass, or None

  • kwargs – Keyword arguments to pass to the metaclass

introspection.resolve_bases(bases)

Clone/backport of types.resolve_bases().

introspection.static_vars(obj)

Like vars(), but bypasses overridden __getattribute__ methods.

Parameters

obj – Any object

Returns

The object’s __dict__

Raises

TypeError – If the object has no __dict__

introspection.static_copy(obj)

Creates a copy of the given object without invoking any of its methods - __new__, __init__, __copy__ or anything else.

How it works:

  1. A new instance of the same class is created by calling object.__new__(type(obj)).

  2. If obj has a __dict__, the new instance’s __dict__ is updated with its contents.

  3. All values stored in __slots__ (except for __dict__ and __weakref__) are assigned to the new object.

An exception are instances of builtin classes - these are copied by calling copy.copy().