Skip to content

[3.8] bpo-43316: gzip: CLI uses non-zero return code on error. (GH-24647) #24649

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 25, 2021
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
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.