{"record":{"id":"1d577a806beff210","repo":"pypa/pip","slug":"could-not-find-adapter-for-registry-and-ob","errorCode":null,"errorMessage":"Could not find adapter for {registry} and {ob}","messagePattern":"Could not find adapter for (.+?) and (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/pip/_vendor/pkg_resources/__init__.py","lineNumber":3498,"sourceCode":"def _always_object(classes):\n    \"\"\"\n    Ensure object appears in the mro even\n    for old-style classes.\n    \"\"\"\n    if object not in classes:\n        return classes + (object,)\n    return classes\n\n\ndef _find_adapter(registry: Mapping[type, _AdapterT], ob: object) -> _AdapterT:\n    \"\"\"Return an adapter factory for `ob` from `registry`\"\"\"\n    types = _always_object(inspect.getmro(getattr(ob, '__class__', type(ob))))\n    for t in types:\n        if t in registry:\n            return registry[t]\n    # _find_adapter would previously return None, and immediately be called.\n    # So we're raising a TypeError to keep backward compatibility if anyone depended on that behaviour.\n    raise TypeError(f\"Could not find adapter for {registry} and {ob}\")\n\n\ndef ensure_directory(path: StrOrBytesPath):\n    \"\"\"Ensure that the parent directory of `path` exists\"\"\"\n    dirname = os.path.dirname(path)\n    os.makedirs(dirname, exist_ok=True)\n\n\ndef _bypass_ensure_directory(path):\n    \"\"\"Sandbox-bypassing version of ensure_directory()\"\"\"\n    if not WRITE_SUPPORT:\n        raise OSError('\"os.mkdir\" not supported on this platform.')\n    dirname, filename = split(path)\n    if dirname and filename and not isdir(dirname):\n        _bypass_ensure_directory(dirname)\n        try:\n            mkdir(dirname, 0o755)\n        except FileExistsError:","sourceCodeStart":3480,"sourceCodeEnd":3516,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_vendor/pkg_resources/__init__.py#L3480-L3516","documentation":"Raised as TypeError in _find_adapter() at line 3498 when no adapter is registered for any type in the MRO of the given object. _find_adapter walks `inspect.getmro(ob.__class__)` looking for a match in the registry dict; if none matches, it raises. This is an internal function used primarily for namespace handler lookup via _namespace_handlers.","triggerScenarios":"An importer object on sys.path whose type (or any base type) is not registered in _namespace_handlers. This is triggered indirectly via _handle_ns -> _find_adapter(_namespace_handlers, importer) at line 2463. Can also fire if _find_adapter is called with a custom registry lacking a matching type.","commonSituations":"A custom or unusual path importer (meta path finder, custom loader) not registered via register_namespace_handler; running under a non-standard Python implementation; extremely old or non-compliant import hooks; this is usually an internal failure rather than a user-facing one.","solutions":["Register a namespace handler for the custom importer type via register_namespace_handler(importer_type, handler).","Use standard import machinery (FileFinder, zipimporter) that pkg_resources already supports.","If using a custom sys.path importer, ensure it subclasses a known importer type.","Catch TypeError around namespace package operations and fall back to PEP 420 implicit namespaces."],"exampleFix":"// before: custom importer not registered\nfrom pkg_resources import _find_adapter, _namespace_handlers\nadapter = _find_adapter(_namespace_handlers, my_custom_importer)\n# TypeError: Could not find adapter for ...\n\n// after\nfrom pkg_resources import register_namespace_handler\nregister_namespace_handler(type(my_custom_importer), my_handler_fn)","handlingStrategy":"try-catch","validationCode":"from pkg_resources import _namespace_handlers\ndef importer_has_handler(importer) -> bool:\n    import inspect\n    types = inspect.getmro(getattr(importer, '__class__', type(importer)))\n    return any(t in _namespace_handlers for t in types)","typeGuard":"from pkg_resources import _namespace_handlers\nimport inspect\ndef is_registered_importer(importer) -> bool:\n    mro = inspect.getmro(getattr(importer, '__class__', type(importer)))\n    return any(t in _namespace_handlers for t in mro)\n","tryCatchPattern":"from pkg_resources import _find_adapter, _namespace_handlers\ntry:\n    handler = _find_adapter(_namespace_handlers, importer)\nexcept TypeError:\n    handler = None  # no registered handler for this importer type\n","preventionTips":["Register namespace handlers for custom importer types via register_namespace_handler().","Use standard importers (FileFinder, zipimporter) that pkg_resources supports.","Catch TypeError around namespace operations when using custom import hooks."],"tags":["internal","pkg-resources","namespace-packages","adapter","importer"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}