Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e3560a7

Browse files
committed
site: error on sitecustomize import error
Issue #26099: The site module now writes an error into stderr if sitecustomize module can be imported but executing the module raise an ImportError. Same change for usercustomize.
1 parent ae8c078 commit e3560a7

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

Lib/site.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -504,9 +504,13 @@ def venv(known_paths):
504504
def execsitecustomize():
505505
"""Run custom site specific code, if available."""
506506
try:
507-
import sitecustomize
508-
except ImportError:
509-
pass
507+
try:
508+
import sitecustomize
509+
except ImportError as exc:
510+
if exc.name == 'sitecustomize':
511+
pass
512+
else:
513+
raise
510514
except Exception as err:
511515
if os.environ.get("PYTHONVERBOSE"):
512516
sys.excepthook(*sys.exc_info())
@@ -520,9 +524,13 @@ def execsitecustomize():
520524
def execusercustomize():
521525
"""Run custom user specific code, if available."""
522526
try:
523-
import usercustomize
524-
except ImportError:
525-
pass
527+
try:
528+
import usercustomize
529+
except ImportError as exc:
530+
if exc.name == 'usercustomize':
531+
pass
532+
else:
533+
raise
526534
except Exception as err:
527535
if os.environ.get("PYTHONVERBOSE"):
528536
sys.excepthook(*sys.exc_info())

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ Core and Builtins
146146
Library
147147
-------
148148

149+
- Issue #26099: The site module now writes an error into stderr if
150+
sitecustomize module can be imported but executing the module raise an
151+
ImportError. Same change for usercustomize.
152+
149153
- Issue #26147: xmlrpc now works with strings not encodable with used
150154
non-UTF-8 encoding.
151155

0 commit comments

Comments
 (0)