Skip to content

Commit 3467028

Browse files
committed
Catch warnings in stdlib
1 parent 2236ed6 commit 3467028

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

Lib/site.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ def joinuser(*args):
320320
def _get_path(userbase):
321321
version = sys.version_info
322322
with warnings.catch_warnings():
323+
# ignore DeprecationWarning on sys.abiflags change
323324
warnings.simplefilter('ignore', DeprecationWarning)
324325
abiflags = getattr(sys, 'abiflags', '')
325326
if 't' in abiflags:
@@ -405,6 +406,7 @@ def getsitepackages(prefixes=None):
405406
implementation = _get_implementation().lower()
406407
ver = sys.version_info
407408
with warnings.catch_warnings():
409+
# ignore DeprecationWarning on sys.abiflags change
408410
warnings.simplefilter('ignore', DeprecationWarning)
409411
abiflags = getattr(sys, 'abiflags', '')
410412
if 't' in abiflags:

Lib/sysconfig/__init__.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ def get_makefile_filename():
335335
return os.path.join(_PROJECT_BASE, "Makefile")
336336

337337
with warnings.catch_warnings():
338+
# ignore DeprecationWarning on sys.abiflags change
338339
warnings.simplefilter('ignore', DeprecationWarning)
339340
has_abiflags = hasattr(sys, 'abiflags')
340341

@@ -511,12 +512,10 @@ def _init_config_vars():
511512
base_prefix = _BASE_PREFIX
512513
base_exec_prefix = _BASE_EXEC_PREFIX
513514

514-
try:
515-
with warnings.catch_warnings():
516-
warnings.simplefilter('ignore', DeprecationWarning)
517-
abiflags = sys.abiflags
518-
except AttributeError:
519-
abiflags = ''
515+
with warnings.catch_warnings():
516+
# ignore DeprecationWarning on sys.abiflags change
517+
warnings.simplefilter('ignore', DeprecationWarning)
518+
abiflags = getattr(sys, 'abiflags', '')
520519

521520
if os.name == 'posix':
522521
_init_posix(_CONFIG_VARS)

Lib/test/pythoninfo.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,13 @@ def get_infos(self):
4747

4848
def copy_attributes(info_add, obj, name_fmt, attributes, *, formatter=None):
4949
for attr in attributes:
50-
value = getattr(obj, attr, None)
50+
if attr == 'abiflags':
51+
with warnings.catch_warnings():
52+
# ignore DeprecationWarning on sys.abiflags change
53+
warnings.simplefilter("ignore", DeprecationWarning)
54+
value = getattr(obj, attr, None)
55+
else:
56+
value = getattr(obj, attr, None)
5157
if value is None:
5258
continue
5359
name = name_fmt % attr

0 commit comments

Comments
 (0)