Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure isinstance(typing_extensions.ParamSpec("P"), typing.TypeVar) is unaffected by sys.setprofile() #407

Merged
merged 13 commits into from
May 23, 2024

Conversation

AlexWaygood
Copy link
Member

@AlexWaygood AlexWaygood commented May 22, 2024

Fixes #318. The workaround here is to avoid the super() call -- the super() call accesses the __class__ variable from the __init__ method, which due to a CPython bug on Python <=3.10 means that __class__ is removed from ParamSpec.__dict__ if a profiling function has been set.

Comment on lines +95 to +96
cd ${path_to_file%.tar.gz}/src
python test_typing_extensions.py
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to make this change or the subprocess wasn't able to import typing_extensions. It was raising ModuleNotFoundError

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With your change it uses the copy of typing_extensions in the repo instead of the installed one; that is incorrect. We shouldn't do this.

Copy link
Member Author

@AlexWaygood AlexWaygood May 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thanks. Do you have any idea why the subprocess wasn't able to import typing_extensions prior to this change, but only for this CI job? I don't fully understand that (see https://github.com/python/typing_extensions/actions/runs/9197903212/job/25299411282?pr=407)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh actually, this might be fine, since in this job we're not attempting to test an installed version of typing_extensions. I'm not actually sure why this doesn't work in CI though. Possibly the test itself is picking up the wrong copy of typing_extensions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually not sure how the pre-existing tests currently pass without this? I think it's correct? Otherwise we unpack the version of typing_extensions we want into an src/ directory, but never cd into that src directory, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's what it looks like.

Comment on lines +5047 to +5054
try:
proc = subprocess.run(
[sys.executable, "-c", code], check=True, capture_output=True, text=True,
)
except subprocess.CalledProcessError as exc:
print("stdout", exc.stdout, sep="\n")
print("stderr", exc.stderr, sep="\n")
raise
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried running this in an isolated scope using exec(), but it was still causing some pollution of the global environment that was causing other, unrelated tests to fail. This seems to be the only way of doing a test with total interpreter isolation.

@AlexWaygood AlexWaygood changed the title Make sure isinstance(typing_extensions.ParamSpec("P"), typing.TypeVar) is unaffected by profiling functions Make sure isinstance(typing_extensions.ParamSpec("P"), typing.TypeVar) is unaffected by sys.setprofile() May 22, 2024
@AlexWaygood AlexWaygood marked this pull request as draft May 23, 2024 20:38
This reverts commit 03a2ade.
This reverts commit ae33db8.
@AlexWaygood AlexWaygood marked this pull request as ready for review May 23, 2024 20:43
@JelleZijlstra
Copy link
Member

The 4.12.0 release should go out today, do you think it's better to merge this in now or wait for the next release? The change seems pretty safe so I think it's fine to merge now in the RC phase.

@AlexWaygood AlexWaygood merged commit 118e1a6 into python:main May 23, 2024
21 checks passed
@AlexWaygood AlexWaygood deleted the isinstance-weirdness branch May 23, 2024 20:50
@AlexWaygood
Copy link
Member Author

The 4.12.0 release should go out today, do you think it's better to merge this in now or wait for the next release? The change seems pretty safe so I think it's fine to merge now in the RC phase.

Oh shoot, sorry -- I merged before seeing this.

I think it's okay to put it into the next release; I agree that this change seems pretty safe. But I also don't think that this issue affects many people, so I would also be fine with cutting the release based on the commit prior to this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

isinstance return different result with sys.setprofile
2 participants