-
-
Notifications
You must be signed in to change notification settings - Fork 31.3k
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
bpo-43316: gzip: CLI uses non-zero return code on error. #24647
Conversation
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.
Thanks @rhpvorderman for the PR, and @methane for merging it 🌮🎉.. I'm working now to backport this PR to: 3.8, 3.9. |
) 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>
GH-24648 is a backport of this pull request to the 3.9 branch. |
) 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>
GH-24649 is a backport of this pull request to the 3.8 branch. |
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>
Thanks @methane ! |
@@ -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)) |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in #24652
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>
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.
In my opinion this change should be backported to all currently supported versions of python. Exiting with 0 upon error is not acceptable behaviour for a tool. Luckily, I think the backport will be quite easy and I am happy to do it.
https://bugs.python.org/issue43316