Skip to content

PyPy: isinstance returns different result with sys.setprofileΒ #661

@brianschubert

Description

@brianschubert

I took a look into the errors from #623 when running PyPy tests under coverage. It seems that the ghost of #318 has come back to haunt us πŸ‘»!

Under PyPy 3.9 and PyPy 3.10, both _UnpackAlias and _ConcatenateGenericAlias have __class__ removed from their class dictionaries when a profiling function has been set.

Here's the output of the script from #318 (comment) under PyPy 3.9:

$ uv run --no-project python --version
Python 3.9.15 (21401ebc2df332b6be6e3d364a985e951a72bbbd, Dec 05 2022, 18:37:07)
[PyPy 7.3.10 with GCC 10.2.1 20210130 (Red Hat 10.2.1-11)]

$ uv run --no-project ./gh318_repro.py
Without profiling function
Global class:  True <class '__main__.A'> Local class:  True <class '__main__.A'>

With profiling function
Global class:  True <class '__main__.A'> Local class:  False None

Without profiling function again
Global class:  True <class '__main__.A'> Local class:  True <class '__main__.A'>

And similarly, the value of _ConcatenateGenericAlias.__class__ with and without coverage:

$ cat temp.py 
from typing_extensions import Concatenate, ParamSpec

P = ParamSpec("P")
C = Concatenate[int, P]
print(type(C).__dict__.get("__class__"))

$ uv run --no-project ./temp.py
<class 'typing._GenericAlias'>

$ uv run --no-project coverage run ./temp.py
None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions