Skip to content

bpo-38937: exec lines from .pth files in a copy of the site.py globals #17414

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

Closed
wants to merge 3 commits into from
Closed

bpo-38937: exec lines from .pth files in a copy of the site.py globals #17414

wants to merge 3 commits into from

Conversation

chrisjbillington
Copy link

@chrisjbillington chrisjbillington commented Nov 28, 2019

Each line of a .pth file is exec()'d in its own namespace, which is a copy of the site module's global namespace. It's a copy so that the code in .pth files can't actually modify the site module just by defining a variable (previously it could!), and it's the globals of the site module rather than an empty dict in order to be backward compatible with .pth files that may be using some of those globals like sys or os without explicitly importing them.

Each line gets its own copy of the namespace, so the lines can't use each other's variables, preserving the deliberate limitation that code in .pth files is limited to one line.

https://bugs.python.org/issue38937

@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).

Recognized GitHub username

We couldn't find a bugs.python.org (b.p.o) account corresponding to the following GitHub usernames:

@chrisjbillington

This might be simply due to a missing "GitHub Name" entry in one's b.p.o account settings. This is necessary for legal reasons before we can look at this contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

Copy link
Member

@isidentical isidentical left a comment

Choose a reason for hiding this comment

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

Can you add a test case to test this behavior.

@csabella
Copy link
Contributor

@chrisjbillington, please address the code review request to add a test. Thank you!

@chrisjbillington
Copy link
Author

Apologies for the delay and thanks for reviewing. I've added a test, and verified that it fails without the change and passes with the change.

@chrisjbillington
Copy link
Author

Pipeline failure appears unrelated, if I'm understanding correctly.

@chrisjbillington chrisjbillington closed this by deleting the head repository Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants