Welcome to jaraco.classes documentation!

For Enterprise

Professional support for jaraco.classes is available as part of the Tidelift Subscription. Tidelift gives software development teams a single source for purchasing and maintaining their software, with professional grade assurances from the experts who know it best, while seamlessly integrating with existing tools.

Learn more Request a Demo

Routines for obtaining the class names of an object and its parent classes.

jaraco.classes.ancestry.all_bases(c)

return a tuple of all base classes the class c has as a parent. >>> object in all_bases(list) True

jaraco.classes.ancestry.all_classes(c)

return a tuple of all classes to which c belongs >>> list in all_classes(list) True

jaraco.classes.ancestry.iter_subclasses(cls, _seen=None)

Generator over all subclasses of a given class, in depth-first order.

>>> bool in list(iter_subclasses(int))
True
>>> class A(object): pass
>>> class B(A): pass
>>> class C(A): pass
>>> class D(B,C): pass
>>> class E(D): pass
>>>
>>> for cls in iter_subclasses(A):
...             print(cls.__name__)
B
D
E
C
>>> # get ALL (new-style) classes currently defined
>>> res = [cls.__name__ for cls in iter_subclasses(object)]
>>> 'type' in res
True
>>> 'tuple' in res
True
>>> len(res) > 100
True

meta.py

Some useful metaclasses.

class jaraco.classes.meta.LeafClassesMeta(name, bases, attrs)

Bases: type

A metaclass for classes that keeps track of all of them that aren’t base classes.

class jaraco.classes.meta.TagRegistered(name, bases, namespace)

Bases: type

As classes of this metaclass are created, they keep a registry in the base class of all classes by a class attribute, indicated by attr_name.

attr_name = 'tag'
class jaraco.classes.properties.ClassPropertyDescriptor(fget, fset=None)

Bases: object

setter(func)
class jaraco.classes.properties.NonDataProperty(fget)

Bases: object

Much like the property builtin, but only implements __get__, making it a non-data property, and can be subsequently reset.

See http://users.rcn.com/python/download/Descriptor.htm for more information.

>>> class X(object):
...   @NonDataProperty
...   def foo(self):
...     return 3
>>> x = X()
>>> x.foo
3
>>> x.foo = 4
>>> x.foo
4
jaraco.classes.properties.classproperty(func)

Indices and tables