8000 _py_abc.ABCMeta.__instancecheck__ is not compatible to abc.ABCMeta.__instancecheck__ · Issue #136047 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content 8000
_py_abc.ABCMeta.__instancecheck__ is not compatible to abc.ABCMeta.__instancecheck__ #136047
Closed
@youknowone

Description

@youknowone

Bug report

Bug description:

When _abc exists, abc.ABCMeta.__instancecheck__ is a thin wrapper of _abc._abc_instancecheck.
Due to the difference of behavior, it seems to related to importlib test

import pathlib
from importlib.resources.readers import MultiplexedPath
from importlib.resources.abc import Traversable
import _abc  # C implementation
import _py_abc  # Pure Python implementation


def test_abc_difference():
    mp = MultiplexedPath(pathlib.Path('/tmp'))

    print(f"Object: {type(mp).__name__}")
    print(f"ABC: {Traversable.__name__}")

    # C implementation (_abc_instancecheck)
    try:
        result_c = _abc._abc_instancecheck(Traversable, mp)
        print(f"C _abc_instancecheck result: {result_c}")
    except Exception as e:
        print(f"C _abc_instancecheck error: {e}")

    # Pure Python implementation (_py_abc.ABCMeta.__instancecheck__)
    try:
        result_py = _py_abc.ABCMeta.__instancecheck__(Traversable, mp)
        print(f"Python _py_abc result: {result_py}")
    except Exception as e:
        print(f"Python _py_abc error: {e}")


if __name__ == "__main__":
    test_abc_difference()

The result:

Object: MultiplexedPath
ABC: Traversable
C _abc_instancecheck error: Protocols with non-method members don't support issubclass(). Non-method members: 'name'.
Python _py_abc error: type object 'Traversable' has no attribute '_abc_cache'

Reproducible on 3.13 and main

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0