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

bpo-30167: site: Ignore TypeError in abs_paths() #6731

Merged
merged 2 commits into from
Jun 11, 2018

Conversation

steverweber
Copy link
Contributor

@steverweber steverweber commented May 8, 2018

Behavior of "os.path.abspath(None)" was changed.

Before Python 3.6, used to report an AttributeError which is properly caught inside "site.abs_paths", making it ignore __main__, one of sys.modules, which has __file__ and __cached__ set to None.

perhaps best to find what sets __cache__ as None and /fix/ that instead of this proposed fix.

https://bugs.python.org/issue30167

https://bugs.python.org/issue30167
change in the behavior of "os.path.abspath(None)". Before Python 3.6, used to report an AttributeError which is properly caught inside "site.abs_paths", making it ignore __main__, one of sys.modules, which has __file__ and __cached__ set to None.
@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 your contribution by verifying you have signed the PSF contributor agreement (CLA).

Unfortunately our records indicate you have not signed the CLA. For legal reasons we need you to sign this before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

When your account is ready, please add a comment in this pull request
and a Python core developer will remove the CLA not signed label
to make the bot check again.

Thanks again to your contribution and we look forward to looking at it!

@steverweber steverweber changed the title issue30167 - TypeError None is not caught bpo-30167 - TypeError None is not caught May 9, 2018
@steverweber
Copy link
Contributor Author

CLA signed yesterday and today. perhaps bot bugged.

@@ -108,7 +108,7 @@ def abs_paths():
pass
try:
m.__cached__ = os.path.abspath(m.__cached__)
except (AttributeError, OSError):
except (AttributeError, OSError, TypeError):
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't line-107 need catching TypeError too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

perhaps it should... However since file seems to be set in most cases it wont cause a TypeError.

@ned-deily
Copy link
Member

Thanks for your contribution, @steverweber. The fix should include a test (In Lib/test/test_site.py) that demonstrates that the problem is fixed and so we don't break it again in the future.

https://devguide.python.org/pullrequest/#making-good-prs

@methane methane changed the title bpo-30167 - TypeError None is not caught bpo-30167: site: Ignore TypeError when __cached__ is None Jun 5, 2018
@methane methane changed the title bpo-30167: site: Ignore TypeError when __cached__ is None bpo-30167: site: Ignore TypeError in abs_paths() Jun 5, 2018
@ned-deily ned-deily merged commit 2487f30 into python:master Jun 11, 2018
@miss-islington
Copy link
Contributor

Thanks @steverweber for the PR, and @ned-deily for merging it 🌮🎉.. I'm working now to backport this PR to: 3.6, 3.7.
🐍🍒⛏🤖

@bedevere-bot
Copy link

GH-7606 is a backport of this pull request to the 3.7 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jun 11, 2018
…thonGH-6731)

Before Python 3.6, os.path.abspath(None) used to report an AttributeError which was properly caught inside site.abs_paths, making it ignore __main__, one of sys.modules, which has __file__ and __cached__ set to None. With 3.6, os.path.abspath(None) raises TypeError instead which site.abs_path was not expecting.  This resulted in an uncaught exception if a user had PYTHONSTARTUP set and the application called site.main() which a number of third-party programs do.
(cherry picked from commit 2487f30)

Co-authored-by: Steve Weber <[email protected]>
@bedevere-bot
Copy link

GH-7607 is a backport of this pull request to the 3.6 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jun 11, 2018
…thonGH-6731)

Before Python 3.6, os.path.abspath(None) used to report an AttributeError which was properly caught inside site.abs_paths, making it ignore __main__, one of sys.modules, which has __file__ and __cached__ set to None. With 3.6, os.path.abspath(None) raises TypeError instead which site.abs_path was not expecting.  This resulted in an uncaught exception if a user had PYTHONSTARTUP set and the application called site.main() which a number of third-party programs do.
(cherry picked from commit 2487f30)

Co-authored-by: Steve Weber <[email protected]>
ned-deily pushed a commit that referenced this pull request Jun 11, 2018
…-6731) (GH-7606)

Before Python 3.6, os.path.abspath(None) used to report an AttributeError which was properly caught inside site.abs_paths, making it ignore __main__, one of sys.modules, which has __file__ and __cached__ set to None. With 3.6, os.path.abspath(None) raises TypeError instead which site.abs_path was not expecting.  This resulted in an uncaught exception if a user had PYTHONSTARTUP set and the application called site.main() which a number of third-party programs do.
(cherry picked from commit 2487f30)

Co-authored-by: Steve Weber <[email protected]>
ned-deily pushed a commit that referenced this pull request Jun 11, 2018
…-6731) (GH-7607)

Before Python 3.6, os.path.abspath(None) used to report an AttributeError which was properly caught inside site.abs_paths, making it ignore __main__, one of sys.modules, which has __file__ and __cached__ set to None. With 3.6, os.path.abspath(None) raises TypeError instead which site.abs_path was not expecting.  This resulted in an uncaught exception if a user had PYTHONSTARTUP set and the application called site.main() which a number of third-party programs do.
(cherry picked from commit 2487f30)

Co-authored-by: Steve Weber <[email protected]>
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.

6 participants