Skip to content

Commit cc3df63

Browse files
authored
bpo-43316: gzip: CLI uses non-zero return code on error. (pythonGH-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.
1 parent 70f8ebe commit cc3df63

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
@@ -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

+4-4
Original file line numberDiff line numberDiff line change
@@ -774,10 +774,10 @@ def test_decompress_infile_outfile(self):
774774
self.assertEqual(err, b'')
775775

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

782782
@create_and_remove_directory(TEMPDIR)
783783
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)