Misc. functions¶
-
introspection.
get_parameters
(callable_)¶ Returns a list of parameters accepted by
callable_
.
-
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 callsresolve_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:
A new instance of the same class is created by calling
object.__new__(type(obj))
.If
obj
has a__dict__
, the new instance’s__dict__
is updated with its contents.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()
.