Skip to content

Commit adea9b8

Browse files
bpo-43316: gzip: CLI uses non-zero return code on error. (GH-24647)
Exit code is now 1 instead of 0. A message is printed to stderr instead of stdout. This is the proper behaviour for a tool that can be used in scripts. (cherry picked from commit cc3df63) Co-authored-by: Ruben Vorderman <[email protected]>
1 parent f82578a commit adea9b8

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

Lib/gzip.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,8 +583,7 @@ def main():
583583
g = sys.stdout.buffer
584584
else:
585585
if arg[-3:] != ".gz":
586-
print("filename doesn't end in .gz:", repr(arg))
587-
continue
586+
sys.exit("filename doesn't end in .gz:", repr(arg))
588587
f = open(arg, "rb")
589588
g = builtins.open(arg[:-3], "wb")
590589
else:

Lib/test/test_gzip.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -772,10 +772,10 @@ def test_decompress_infile_outfile(self):
772772
self.assertEqual(err, b'')
773773

774774
def test_decompress_infile_outfile_error(self):
775-
rc, out, err = assert_python_ok('-m', 'gzip', '-d', 'thisisatest.out')
776-
self.assertIn(b"filename doesn't end in .gz:", out)
777-
self.assertEqual(rc, 0)
778-
self.assertEqual(err, b'')
775+
rc, out, err = assert_python_failure('-m', 'gzip', '-d', 'thisisatest.out')
776+
self.assertIn(b"filename doesn't end in .gz:", err)
777+
self.assertEqual(rc, 1)
778+
self.assertEqual(out, b'')
779779

780780
@create_and_remove_directory(TEMPDIR)
781781
def test_compress_stdin_outfile(self):
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The ``python -m gzip`` command line application now properly fails when
2+
detecting an unsupported extension. It exits with a non-zero exit code and
3+
prints an error message to stderr.

0 commit comments

Comments
 (0)