Abstract Classes

pcapkit.utilities.inspect holds isabstract(), which tells an abstract class from a concrete one without the interpreter’s abstract flag, so the answer is the same on every interpreter, during __init_subclass__() and after the class is made (#2784). Protocol.__init_subclass__ decides with it whether a class names itself in the by-name registry. It behaves the same everywhere rather than gating on a version, so it is not in compat; see Choosing Between utilities and corekit.

Added in version 1.6.0.

pcapkit.utilities.inspect.isabstract(cls)[source]

Whether cls is an abstract class, without its __flags__.

A class made by abc.ABCMeta is abstract when its own namespace holds an abstract method, or when a name one of its bases lists in __abstractmethods__ still resolves to an abstract method on it. That is how abc.ABCMeta computes __abstractmethods__, so the answer agrees with it after the class is made, and is already the same while __init_subclass__() runs, before abc.ABCMeta has set it. inspect.isabstract() takes the same route there, but reads the interpreter’s abstract flag first.

Parameters:

cls (Any) – Object to check. Anything other than a class made by abc.ABCMeta is not abstract.

Return type:

bool

Returns:

Whether cls is abstract.