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
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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn’t this use string concatenation or f-string to pass one argument to sys.exit?

Signature is sys.exit(status=None)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right! We can not pass two strings to sys.exit().
I don't know why this passed the test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I got it. The stderr is:

Traceback (most recent call last):
(snip)
  File "/Users/inada-n/work/python/cpython/Lib/gzip.py", line 586, in main
    sys.exit("filename doesn't end in .gz:", repr(arg))
TypeError: exit expected at most 1 argument, got 2

And it passes the test self.assertIn(b"filename doesn't end in .gz:", err).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in #24652

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.