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.
diff --git a/Lib/gzip.py b/Lib/gzip.py
index e422773..8002b43 100644
--- a/Lib/gzip.py
+++ b/Lib/gzip.py
@@ -583,8 +583,7 @@ def main():
g = sys.stdout.buffer
else:
if arg[-3:] != ".gz":
- print("filename doesn't end in .gz:", repr(arg))
- continue
+ sys.exit("filename doesn't end in .gz:", repr(arg))
f = open(arg, "rb")
g = builtins.open(arg[:-3], "wb")
else:
diff --git a/Lib/test/test_gzip.py b/Lib/test/test_gzip.py
index c3fa9b0..1bb8f7a 100644
--- a/Lib/test/test_gzip.py
+++ b/Lib/test/test_gzip.py
@@ -774,10 +774,10 @@ def test_decompress_infile_outfile(self):
self.assertEqual(err, b'')
def test_decompress_infile_outfile_error(self):
- rc, out, err = assert_python_ok('-m', 'gzip', '-d', 'thisisatest.out')
- self.assertIn(b"filename doesn't end in .gz:", out)
- self.assertEqual(rc, 0)
- self.assertEqual(err, b'')
+ rc, out, err = assert_python_failure('-m', 'gzip', '-d', 'thisisatest.out')
+ self.assertIn(b"filename doesn't end in .gz:", err)
+ self.assertEqual(rc, 1)
+ self.assertEqual(out, b'')
@create_and_remove_directory(TEMPDIR)
def test_compress_stdin_outfile(self):