Skip to content

Commit 2487f30

Browse files
steverweberned-deily
authored andcommitted
bpo-30167: Prevent site.main() exception if PYTHONSTARTUP is set. (GH-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.
1 parent 8398713 commit 2487f30

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

Lib/site.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,11 @@ def abs_paths():
104104
continue # don't mess with a PEP 302-supplied __file__
105105
try:
106106
m.__file__ = os.path.abspath(m.__file__)
107-
except (AttributeError, OSError):
107+
except (AttributeError, OSError, TypeError):
108108
pass
109109
try:
110110
m.__cached__ = os.path.abspath(m.__cached__)
111-
except (AttributeError, OSError):
111+
except (AttributeError, OSError, TypeError):
112112
pass
113113

114114

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,6 +1721,7 @@ David Watson
17211721
Aaron Watters
17221722
Henrik Weber
17231723
Leon Weber
1724+
Steve Weber
17241725
Corran Webster
17251726
Glyn Webster
17261727
Phil Webster
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Prevent site.main() exception if PYTHONSTARTUP is set. Patch by Steve Weber.

0 commit comments

Comments
 (0)