Classes

Relationship among Classes

There are some more APIs that extend the Python built-in function issubclass().

calcpy.ispropersubclass(*args)

Returns True if a argument is a proper subclass of the follow-up argument.

Parameters:

*args (type | tuple[type] | UnionType) – Classes to check

Returns:

True if all arguments are proper subclasses of the follow-up arguments

Return type:

bool

Examples

>>> class A: pass
>>> class B(A): pass
>>> class C(B): pass
>>> class D(A): pass
>>> ispropersubclass()
True
>>> ispropersubclass(object)
True
>>> ispropersubclass(A, object)
True
>>> ispropersubclass(C, B, A, object)
True
>>> ispropersubclass(D, C)
False
>>> ispropersubclass(A, A)
False
calcpy.ispropersuperclass(*args)

Returns True if a argument is a proper superclasses of the follow-up argument.

Parameters:

*args (type | tuple[type] | UnionType) – Classes to check

Returns:

True if all arguments are proper superclasses of the follow-up arguments

Return type:

bool

Examples

>>> class A: pass
>>> class B(A): pass
>>> class C(B): pass
>>> class D(A): pass
>>> ispropersuperclass()
True
>>> ispropersuperclass(A)
True
>>> ispropersuperclass(object, A)
True
>>> ispropersuperclass(object, A, B, C)
True
>>> ispropersuperclass(D, C)
False
>>> ispropersuperclass(A, A)
False
calcpy.issubclass_(*args)

Returns True if a argument is a subclass of the follow-up argument.

Parameters:

*args (type | tuple[type] | UnionType) – Classes to check

Returns:

True if all arguments are subclasses of the follow-up arguments

Return type:

bool

Examples

>>> class A: pass
>>> class B(A): pass
>>> class C(B): pass
>>> class D(A): pass
>>> issubclass_()
True
>>> issubclass_(object)
True
>>> issubclass_(A, object)
True
>>> issubclass_(C, B, A, object)
True
>>> issubclass_(D, C)
False
>>> issubclass_(A, A)
True
calcpy.issuperclass(*args)

Returns True if a argument is a superclasses of the follow-up argument.

Parameters:

*args (type | tuple[type] | UnionType) – Classes to check

Returns:

True if all arguments are superclasses of the follow-up arguments

Return type:

bool

Examples

>>> class A: pass
>>> class B(A): pass
>>> class C(B): pass
>>> class D(A): pass
>>> issuperclass()
True
>>> issuperclass(A)
True
>>> issuperclass(A, B)
True
>>> issuperclass(object, A, B, C)
True
>>> issuperclass(D, C)
False
>>> issuperclass(A, A)
True