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

SUPPORTED_ABCS

Ordered list of ABC types analysed during lookup, including str and bytes so callers can easily distinguish literal-like sequences from general collections.

SUPPORTED_BASES

Concrete builtin bases tested when deriving key/value arguments for ABCs.

ABC_MAPPINGS

Immutable mapping from supported ABCs to their lookup metadata.

Functions

get_abc_info()

Public wrapper around _get_abc_info() that always returns an entry.

get_class_attribute_abc_info(namespace, attr)

Return ABCInfo for a cached collection attribute on cls if known.

Classes

ABCInfo

Detailed information about a collection ABC or concrete collection type.

ABCLookupInfo

Runtime metadata describing an ABC and its related concrete bases.