]> granicus.if.org Git - python/commitdiff
bpo-30167: Prevent site.main() exception if PYTHONSTARTUP is set. (GH-6731) (GH-7606)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 11 Jun 2018 01:21:35 +0000 (18:21 -0700)
committerNed Deily <nad@python.org>
Mon, 11 Jun 2018 01:21:35 +0000 (21:21 -0400)
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@gmail.com>
Lib/site.py
Misc/ACKS
Misc/NEWS.d/next/Library/2018-06-10-19-29-17.bpo-30167.G5EgC5.rst [new file with mode: 0644]

index 950e7038a505939bb177a5784a4a060278fce3c3..4595244e2f5a78ea3ef0b651e3885d1188862f09 100644 (file)
@@ -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
 
 
index 31ad80f8bc9c98951e6ecf656f4555551673f46d..7234c0a766fdaadcfbb889fe1acb5cdd67a52e91 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1713,6 +1713,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 (file)
index 0000000..072a001
--- /dev/null
@@ -0,0 +1 @@
+Prevent site.main() exception if PYTHONSTARTUP is set. Patch by Steve Weber.