Skip to content

Commit f94a74e

Browse files
committed
Silence deprecation warning starting in Python 3.12
1 parent 633656f commit f94a74e

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

pyomo/common/download.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,10 +439,20 @@ def filter_fcn(info):
439439
# Strip high bits & group/other write bits
440440
info.mode &= 0o755
441441
return True
442-
442+
if sys.version_info[:2] < (3,12):
443+
tar_args = {}
444+
else:
445+
# Add a tar filter to suppress deprecation warning in Python 3.12+
446+
#
447+
# Note that starting in Python 3.14 the default is 'data',
448+
# however, this method is already filtering for many of the
449+
# things that 'data' would catch (and raise an exception
450+
# for). For backwards compatibility, we will use the more
451+
# permissive "tar" filter.
452+
tar_args = {'filter': tarfile.tar_filter}
443453
with tarfile.open(fileobj=io.BytesIO(self.retrieve_url(url))) as TAR:
444454
dest = os.path.realpath(self._fname)
445-
TAR.extractall(dest, filter(filter_fcn, TAR.getmembers()))
455+
TAR.extractall(dest, filter(filter_fcn, TAR.getmembers()), **tar_args)
446456

447457
def get_gzipped_binary_file(self, url):
448458
if self._fname is None:

0 commit comments

Comments
 (0)