Skip to content

Commit ec4343c

Browse files
miss-islingtonsteverweber
authored andcommitted
bpo-30167: Prevent site.main() exception if PYTHONSTARTUP is set. (GH-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 <[email protected]>
1 parent 037e912 commit ec4343c

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
@@ -1713,6 +1713,7 @@ David Watson
17131713
Aaron Watters
17141714
Henrik Weber
17151715
Leon Weber
1716+
Steve Weber
17161717
Corran Webster
17171718
Glyn Webster
17181719
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)