{"record":{"id":"bac9b1541b153d45","repo":"python/cpython","slug":"module-collections-abc-has-no-attribute-attr-r","errorCode":null,"errorMessage":"module 'collections.abc' has no attribute {attr!r}","messagePattern":"module 'collections\\.abc' has no attribute (.+?)","errorType":"exception","errorClass":"AttributeError","httpStatus":null,"severity":"error","filePath":"Lib/_collections_abc.py","lineNumber":1181,"sourceCode":"        del self[self.index(value)]\n\n    def __iadd__(self, values):\n        self.extend(values)\n        return self\n\n\nMutableSequence.register(list)\nMutableSequence.register(bytearray)\n\n_deprecated_ByteString = globals().pop(\"ByteString\")\n\ndef __getattr__(attr):\n    if attr == \"ByteString\":\n        import warnings\n        warnings._deprecated(\"collections.abc.ByteString\", remove=(3, 17))\n        globals()[\"ByteString\"] = _deprecated_ByteString\n        return _deprecated_ByteString\n    raise AttributeError(f\"module 'collections.abc' has no attribute {attr!r}\")\n","sourceCodeStart":1163,"sourceCodeEnd":1182,"githubUrl":"https://github.com/python/cpython/blob/bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6/Lib/_collections_abc.py#L1163-L1182","documentation":"AttributeError raised by the module-level __getattr__ in Lib/_collections_abc.py for any attribute of collections.abc that does not exist (after the ByteString deprecation shim is consulted). The module defines __getattr__ solely to service the deprecated 'ByteString' alias; every other missing-name lookup falls through to this explicit error.","triggerScenarios":"collections.abc.Bytearray (typo for ByteString/Bytearray mismatch), collections.abc.mappping, or any attribute access on the module that is not one of its ABCs. Also triggered by hasattr-driven feature detection and getattr(collections.abc, name) with dynamic names.","commonSituations":"Attribute typos in imports ('from collections.abc import Iterble'); code assuming a newer ABC (e.g. Buffer) exists on an older Python; IDE-autocompleted but nonexistent names; migration from collections container ABCs to collections.abc where names differ (e.g. collections.Mapping vs collections.abc.Mapping).","solutions":["Check the spelling against dir(collections.abc) or the docs for your Python version.","For version-dependent ABCs, guard with getattr(collections.abc, 'Buffer', None) or hasattr before access.","Replace old collections.X usages with collections.abc.X (Mapping, Sequence, Iterable, ...).","Note collections.abc.ByteString is deprecated for removal (3.17) — migrate to Sequence/bytes checks now to avoid this error later."],"exampleFix":"# before\nfrom collections.abc import ByteString  # works today, removal scheduled (3.17)\nx = collections.abc.Itrable  # AttributeError\n\n# after\nfrom collections.abc import Sequence\nx = collections.abc.Iterable\nBuffer = getattr(collections.abc, 'Buffer', None)  # version-safe feature detection","handlingStrategy":"validation","validationCode":"import collections.abc as cabc\n\nname = 'Buffer'\nABC = getattr(cabc, name, None)\nif ABC is None:\n    raise NotImplementedError(f'collections.abc.{name} not on Python {sys.version_info}')","typeGuard":"def abc_exists(name: str) -> bool:\n    import collections.abc as cabc\n    return name in dir(cabc) or name == 'ByteString'  # shimmed name","tryCatchPattern":"try:\n    ABC = getattr(collections.abc, name)\nexcept AttributeError as e:\n    if 'has no attribute' in str(e):\n        ABC = None  # feature absent on this Python; use fallback path\n    else:\n        raise","preventionTips":["Use getattr(..., None) for version-dependent ABCs.","Run mypy with the minimum supported Python version to catch missing names.","Migrate off deprecated names (ByteString) before the removal release (3.17)."],"tags":["collections-abc","attributeerror","deprecation","developer-error"],"backgroundTag":null,"analyzedSha":"bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6","analyzedAt":"2026-08-14T22:01:13.976Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}