[Python-checkins] bpo-30167: Prevent site.main() exception if PYTHONSTARTUP is set. (GH-6731) (GH-7607)

Ned Deily webhook-mailer at python.org
Sun Jun 10 21:23:44 EDT 2018


https://github.com/python/cpython/commit/3e121581d008a780b8a9f1bcda5966cf0c06f6d5
commit: 3e121581d008a780b8a9f1bcda5966cf0c06f6d5
branch: 3.6
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: Ned Deily <nad at python.org>
date: 2018-06-10T21:23:41-04:00
summary:

bpo-30167: Prevent site.main() exception if PYTHONSTARTUP is set. (GH-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 2487f30d5529948ace26559e274d7cac6abcd1a8)

Co-authored-by: Steve Weber <steverweber at gmail.com>

files:
A Misc/NEWS.d/next/Library/2018-06-10-19-29-17.bpo-30167.G5EgC5.rst
M Lib/site.py
M Misc/ACKS

diff --git a/Lib/site.py b/Lib/site.py
index 0fc92009e19a..1bd63ccf6a23 100644
--- a/Lib/site.py
+++ b/Lib/site.py
@@ -104,11 +104,11 @@ def abs_paths():
             continue   # don't mess with a PEP 302-supplied __file__
         try:
             m.__file__ = os.path.abspath(m.__file__)
-        except (AttributeError, OSError):
+        except (AttributeError, OSError, TypeError):
             pass
         try:
             m.__cached__ = os.path.abspath(m.__cached__)
-        except (AttributeError, OSError):
+        except (AttributeError, OSError, TypeError):
             pass
 
 
diff --git a/Misc/ACKS b/Misc/ACKS
index 8414b9140f51..93e65a4bbf2e 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1666,6 +1666,7 @@ David Watson
 Aaron Watters
 Henrik Weber
 Leon Weber
+Steve Weber
 Corran Webster
 Glyn Webster
 Phil Webster
diff --git a/Misc/NEWS.d/next/Library/2018-06-10-19-29-17.bpo-30167.G5EgC5.rst b/Misc/NEWS.d/next/Library/2018-06-10-19-29-17.bpo-30167.G5EgC5.rst
new file mode 100644
index 000000000000..072a001adab8
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-06-10-19-29-17.bpo-30167.G5EgC5.rst
@@ -0,0 +1 @@
+Prevent site.main() exception if PYTHONSTARTUP is set. Patch by Steve Weber.



More information about the Python-checkins mailing list