Mailing List Archive

bpo-43316: gzip: CLI uses non-zero return code on error. (GH-24647)
https://github.com/python/cpython/commit/cc3df6368d4f3f6c9c9b716876c7e7b79c7abf3f
commit: cc3df6368d4f3f6c9c9b716876c7e7b79c7abf3f
branch: master
author: Ruben Vorderman <r.h.p.vorderman@lumc.nl>
committer: methane <songofacandy@gmail.com>
date: 2021-02-25T20:30:24+09:00
summary:

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.

files:
A Misc/NEWS.d/next/Library/2021-02-25-09-44-36.bpo-43316.k9Gyqn.rst
M Lib/gzip.py
M Lib/test/test_gzip.py

diff --git a/Lib/gzip.py b/Lib/gzip.py
index e422773b3edfb..8002b43bde97c 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 c3fa9b097f8aa..1bb8f7a2d351c 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):
diff --git a/Misc/NEWS.d/next/Library/2021-02-25-09-44-36.bpo-43316.k9Gyqn.rst b/Misc/NEWS.d/next/Library/2021-02-25-09-44-36.bpo-43316.k9Gyqn.rst
new file mode 100644
index 0000000000000..1f0d3c499c16f
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2021-02-25-09-44-36.bpo-43316.k9Gyqn.rst
@@ -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.

_______________________________________________
Python-checkins mailing list
Python-checkins@python.org
https://mail.python.org/mailman/listinfo/python-checkins
bpo-43316: gzip: CLI uses non-zero return code on error. (GH-24647) [ In reply to ]
https://github.com/python/cpython/commit/69906c505b139cbd892866dbceeb607eff53ab3b
commit: 69906c505b139cbd892866dbceeb607eff53ab3b
branch: 3.8
author: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
committer: miss-islington <31488909+miss-islington@users.noreply.github.com>
date: 2021-02-25T03:52:11-08:00
summary:

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 cc3df6368d4f3f6c9c9b716876c7e7b79c7abf3f)

Co-authored-by: Ruben Vorderman <r.h.p.vorderman@lumc.nl>

files:
A Misc/NEWS.d/next/Library/2021-02-25-09-44-36.bpo-43316.k9Gyqn.rst
M Lib/gzip.py
M Lib/test/test_gzip.py

diff --git a/Lib/gzip.py b/Lib/gzip.py
index 87b553df66cd8..3dd8564bec35d 100644
--- a/Lib/gzip.py
+++ b/Lib/gzip.py
@@ -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:
diff --git a/Lib/test/test_gzip.py b/Lib/test/test_gzip.py
index 646828621a53c..4bbc7424eb8a5 100644
--- a/Lib/test/test_gzip.py
+++ b/Lib/test/test_gzip.py
@@ -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):
diff --git a/Misc/NEWS.d/next/Library/2021-02-25-09-44-36.bpo-43316.k9Gyqn.rst b/Misc/NEWS.d/next/Library/2021-02-25-09-44-36.bpo-43316.k9Gyqn.rst
new file mode 100644
index 0000000000000..1f0d3c499c16f
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2021-02-25-09-44-36.bpo-43316.k9Gyqn.rst
@@ -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.

_______________________________________________
Python-checkins mailing list
Python-checkins@python.org
https://mail.python.org/mailman/listinfo/python-checkins
bpo-43316: gzip: CLI uses non-zero return code on error. (GH-24647) [ In reply to ]
https://github.com/python/cpython/commit/adea9b86a97794ca75054603497c195d5ba39aa5
commit: adea9b86a97794ca75054603497c195d5ba39aa5
branch: 3.9
author: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
committer: methane <songofacandy@gmail.com>
date: 2021-02-26T10:13:17+09:00
summary:

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 cc3df6368d4f3f6c9c9b716876c7e7b79c7abf3f)

Co-authored-by: Ruben Vorderman <r.h.p.vorderman@lumc.nl>

files:
A Misc/NEWS.d/next/Library/2021-02-25-09-44-36.bpo-43316.k9Gyqn.rst
M Lib/gzip.py
M Lib/test/test_gzip.py

diff --git a/Lib/gzip.py b/Lib/gzip.py
index e422773b3edfb..8002b43bde97c 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 0f235d1805e0d..66ae51acbff54 100644
--- a/Lib/test/test_gzip.py
+++ b/Lib/test/test_gzip.py
@@ -772,10 +772,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):
diff --git a/Misc/NEWS.d/next/Library/2021-02-25-09-44-36.bpo-43316.k9Gyqn.rst b/Misc/NEWS.d/next/Library/2021-02-25-09-44-36.bpo-43316.k9Gyqn.rst
new file mode 100644
index 0000000000000..1f0d3c499c16f
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2021-02-25-09-44-36.bpo-43316.k9Gyqn.rst
@@ -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.

_______________________________________________
Python-checkins mailing list
Python-checkins@python.org
https://mail.python.org/mailman/listinfo/python-checkins