First common ancestor

pythonic_fp.gadgets.first_common_ancestor(cls1: type, cls2: type) type

Least upper bound

Find the least upper bound in the inheritance graph of two classes.

param cls1:

A class in the inheritance hierarchy.

param cls2:

A class in the inheritance hierarchy.

returns:

First common ancestor based on getmro order.

raises TypeError:

Raised when no common ancestor exists, or when not caught when raised by inspect.getmro.

Warning

This function can fail with a TypeError. Some error messages seen are

  • multiple bases have instance lay-out conflict

  • type ‘bool’ is not an acceptable base type

This happens frequently when the function is given Python builtin types or in multiple inheritance situations.