Skip to content

Commit 3e12158

Browse files
miss-islingtonsteverweber
authored andcommitted
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 2487f30) Co-authored-by: Steve Weber <steverweber@gmail.com>
1 parent 1d4089b commit 3e12158

3 files changed

Lines changed: 4 additions & 2 deletions

File tree

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
@@ -1666,6 +1666,7 @@ David Watson
16661666
Aaron Watters
16671667
Henrik Weber
16681668
Leon Weber
1669+
Steve Weber
16691670
Corran Webster
16701671
Glyn Webster
16711672
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)