abc_info
Helpers for inspecting abstract base classes (ABCs).
This module centralises metadata needed to reason about runtime ABCs and the standard collection ABC hierarchy. It provides:
curated lists of supported ABC types and commonly used concrete bases,
pre-computed lookup tables for quickly mapping between ABCs and compatible base classes, and
high-level helpers that resolve the concrete key/value types declared by generic collections or inferred from a concrete instance.
String-like sequences such as str
and bytes
are explicitly represented in SUPPORTED_ABCS
so callers can detect when string literals are being
treated as collections in generic code paths.
The resolved information is exposed via ABCInfo
, an immutable structure that provides convenient properties for inspecting the collection’s
capabilities and declared key/value types.
Examples
1. Inspect a built-in mapping instance
>>> from app.util.helpers import abc_info
>>> info = abc_info.get_abc_info([1, 2, 3])
>>> info.sequence
True
>>> info.mutable
True
2. Resolve collection metadata from class annotations
>>> class ContainsMapping:
... data: dict[str, float]
>>> info = abc_info.get_class_attribute_abc_info(ContainsMapping, "data")
>>> info.mapping
True
>>> info.key_type
<class 'str'>
>>> info.value_type
<class 'float'>
Module Attributes
Ordered list of ABC types analysed during lookup, including |
|
Concrete builtin bases tested when deriving key/value arguments for ABCs. |
|
Immutable mapping from supported ABCs to their lookup metadata. |
Functions
Public wrapper around |
|
|
Return |
Classes
Detailed information about a collection ABC or concrete collection type. |
|
Runtime metadata describing an ABC and its related concrete bases. |