Skip to content

Commit 69906c5

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 <r.h.p.vorderman@lumc.nl>
1 parent 2a9e6ab commit 69906c5

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

Lib/gzip.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -575,8 +575,7 @@ def main():
575575
g = sys.stdout.buffer
576576
else:
577577
if arg[-3:] != ".gz":
578-
print("filename doesn't end in .gz:", repr(arg))
579-
continue
578+
sys.exit("filename doesn't end in .gz:", repr(arg))
580579
f = open(arg, "rb")
581580
g = builtins.open(arg[:-3], "wb")
582581
else:

Lib/test/test_gzip.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -760,10 +760,10 @@ def test_decompress_infile_outfile(self):
760760
self.assertEqual(err, b'')
761761

762762
def test_decompress_infile_outfile_error(self):
763-
rc, out, err = assert_python_ok('-m', 'gzip', '-d', 'thisisatest.out')
764-
self.assertIn(b"filename doesn't end in .gz:", out)
765-
self.assertEqual(rc, 0)
766-
self.assertEqual(err, b'')
763+
rc, out, err = assert_python_failure('-m', 'gzip', '-d', 'thisisatest.out')
764+
self.assertIn(b"filename doesn't end in .gz:", err)
765+
self.assertEqual(rc, 1)
766+
self.assertEqual(out, b'')
767767

768768
@create_and_remove_directory(TEMPDIR)
769769
def test_compress_stdin_outfile(self):
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)