Title: Argparse Tutorial - unreasonable operators
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.7
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Culip, aldwinaldwin, docs@python, paul.j3, serhiy.storchaka, zach.ware
Priority: normal Keywords: patch

Created on 2019-07-10 11:54 by Culip, last changed 2019-07-11 17:46 by serhiy.storchaka. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 14697 closed aldwinaldwin, 2019-07-11 03:37
Messages (5)
msg347617 - (view) Author: Nathan Oyama (Culip) Date: 2019-07-10 11:54
In "Python 3.7 Documentation > Python HOWTOs > Argparse Tutorial" (, search this page for

elif args.verbosity >= 1:

The operator ">=" should read "==" because args.verbosity cannot be 2 or greater after the if statement.

You would find the original codes unreasonable until you go through "if args.verbosity >= 1:".
msg347651 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2019-07-11 04:53
I don't agree with the proposed change; I think the examples are fine as is.

Using `>= 1` means if you later decide that the `-vv` message should actually only happen at `-vvv` and `-vv` should get the same message as `-v`, you only have to change the 2 to a 3 and you're done.  With `== 1` you have to remember to either change `== 1` to `>= 1` or switch to `in {1, 2}`, or (more likely) forget to make the change initially and have to go back and fix it later.

The last example especially must not be changed; it is explicitly showing how to emit additional messages at higher verbosity levels.

I recommend closing this issue.
msg347655 - (view) Author: Aldwin Pollefeyt (aldwinaldwin) * Date: 2019-07-11 05:52
The >= is unnecessary in this exact example, as is correctly noted by Nathan.

I understand using >= for future purposes, after you explained, what is also correct but confusing because you specifically describe why you change the >= 2, but it doesn't make sense for >= 1 then.

For the last example, I might be completely wrong (please don't shoot me), IMHO it can be == 1 also? It is not 'explicitly showing how to emit additional messages at higher verbosity levels', but to 'uses verbosity level to display more text'. So, removing the 'else' statement to always print(answer), no matter which verbosity is shown.

To avoid confusion, I recommend the change and please have another look at the last statement that makes no difference in using == or >=.
msg347657 - (view) Author: Aldwin Pollefeyt (aldwinaldwin) * Date: 2019-07-11 07:46
@Zachary, you are right ... the last one should be >= 1. Now i see the difference with the previous examples. It changed the output drastically from "the square of {} equals {}" vs "{}^2 == {}" to suddenly printing the filename at -vv. I was focused more on the structural change to always print answer. ... I will adjust.
msg347696 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-07-11 17:46
I concur with Zachary. The current writing is more errorproof.
Date User Action Args
2019-07-11 17:46:44serhiy.storchakasetstatus: open -> closed

nosy: + serhiy.storchaka
messages: + msg347696

resolution: rejected
stage: patch review -> resolved
2019-07-11 07:46:03aldwinaldwinsetmessages: + msg347657
2019-07-11 05:52:30aldwinaldwinsetmessages: + msg347655
2019-07-11 04:53:26zach.waresetnosy: + zach.ware
messages: + msg347651
2019-07-11 03:38:34aldwinaldwinsetnosy: + aldwinaldwin
2019-07-11 03:37:44aldwinaldwinsetkeywords: + patch
stage: patch review
pull_requests: + pull_request14497
2019-07-10 17:14:06xtreaksetnosy: + paul.j3
2019-07-10 11:54:30Culipcreate