Skip to content

Commit ab8f926

Browse files
committed
Add optional exc=None to _trace()
There were a few too-chatty call sites where parse-time errors were being reported as errors unconditionally instead of only when -v was given.
1 parent 261088d commit ab8f926

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

Lib/site.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@
6565
USER_BASE = None
6666

6767

68-
def _trace(message):
68+
def _trace(message, exc=None):
6969
if sys.flags.verbose:
70-
print(message, file=sys.stderr)
70+
_print_error(message, exc)
7171

7272

7373
def _print_error(message, exc=None):
@@ -166,7 +166,7 @@ def _read_pthstart_file(sitedir, name, suffix):
166166
try:
167167
st = os.lstat(filename)
168168
except OSError as exc:
169-
_print_error(f"Cannot stat {filename!r}", exc)
169+
_trace(f"Cannot stat {filename!r}", exc)
170170
return None, filename
171171

172172
if ((getattr(st, 'st_flags', 0) & stat.UF_HIDDEN) or
@@ -179,7 +179,7 @@ def _read_pthstart_file(sitedir, name, suffix):
179179
with io.open_code(filename) as f:
180180
raw_content = f.read()
181181
except OSError as exc:
182-
_print_error(f"Cannot read {filename!r}", exc)
182+
_trace(f"Cannot read {filename!r}", exc)
183183
return None, filename
184184

185185
try:
@@ -224,8 +224,7 @@ def _read_pth_file(sitedir, name, known_paths):
224224
try:
225225
dir_, dircase = makepath(sitedir, line)
226226
except Exception as exc:
227-
_print_error(
228-
f"Error in {filename!r}, line {n:d}: {line!r}", exc)
227+
_trace(f"Error in {filename!r}, line {n:d}: {line!r}", exc)
229228
continue
230229

231230
if dircase in known_paths:

0 commit comments

Comments
 (0)