Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
  • Loading branch information
rhpvorderman authored and miss-islington committed Feb 25, 2021
commit 8139730befb5f4670d77349b7b7a960af79ca153
3 changes: 1 addition & 2 deletions Lib/gzip.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,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:
Expand Down
8 changes: 4 additions & 4 deletions Lib/test/test_gzip.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,10 +760,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):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The ``python -m gzip`` command line application now properly fails when
detecting an unsupported extension. It exits with a non-zero exit code and
prints an error message to stderr.