bpo-30167: site: Ignore TypeError in abs_paths()#6731
Conversation
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.
|
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 Thanks again to your contribution and we look forward to looking at it! |
|
CLA signed yesterday and today. perhaps bot bugged. |
| try: | ||
| m.__cached__ = os.path.abspath(m.__cached__) | ||
| except (AttributeError, OSError): | ||
| except (AttributeError, OSError, TypeError): |
There was a problem hiding this comment.
Doesn't line-107 need catching TypeError too?
There was a problem hiding this comment.
perhaps it should... However since file seems to be set in most cases it wont cause a TypeError.
|
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. |
|
Thanks @steverweber for the PR, and @ned-deily for merging it 🌮🎉.. I'm working now to backport this PR to: 3.6, 3.7. |
|
GH-7606 is a backport of this pull request to the 3.7 branch. |
…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 <steverweber@gmail.com>
|
GH-7607 is a backport of this pull request to the 3.6 branch. |
…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 <steverweber@gmail.com>
…-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 <steverweber@gmail.com>
…-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 <steverweber@gmail.com>
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