Skip to content

Commit

Permalink
bpo-43316: gzip: CLI uses non-zero return code on error. (pythonGH-24647
Browse files Browse the repository at this point in the history
)

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.
  • Loading branch information
rhpvorderman authored Feb 25, 2021
1 parent 70f8ebe commit cc3df63
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
3 changes: 1 addition & 2 deletions Lib/gzip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
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 @@ -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):
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.

0 comments on commit cc3df63

Please sign in to comment.