python / cpython

The Python programming language
https://www.python.org/
Other
61.16k stars 29.52k forks source link

Python 2 error in Argparse tutorial #61067

Closed cf65f861-413d-442f-a4e8-82177d99568a closed 9 years ago

cf65f861-413d-442f-a4e8-82177d99568a commented 11 years ago
BPO 16863
Nosy @terryjreedy, @ezio-melotti, @bitdancer, @berkerpeksag, @phmc

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields: ```python assignee = 'https://github.com/terryjreedy' closed_at = created_at = labels = ['easy', 'type-feature', 'docs'] title = 'Python 2 error in Argparse tutorial' updated_at = user = 'https://bugs.python.org/CharlieDimino' ``` bugs.python.org fields: ```python activity = actor = 'terry.reedy' assignee = 'terry.reedy' closed = True closed_date = closer = 'terry.reedy' components = ['Documentation'] creation = creator = 'Charlie.Dimino' dependencies = [] files = [] hgrepos = [] issue_num = 16863 keywords = ['easy'] message_count = 11.0 messages = ['179041', '179043', '179044', '179045', '179050', '179052', '179108', '179115', '229836', '229837', '229839'] nosy_count = 9.0 nosy_names = ['terry.reedy', 'ezio.melotti', 'r.david.murray', 'docs@python', 'tshepang', 'python-dev', 'berker.peksag', 'pconnell', 'Charlie.Dimino'] pr_nums = [] priority = 'normal' resolution = 'fixed' stage = 'resolved' status = 'closed' superseder = None type = 'enhancement' url = 'https://bugs.python.org/issue16863' versions = ['Python 2.7'] ```

cf65f861-413d-442f-a4e8-82177d99568a commented 11 years ago

http://docs.python.org/2/howto/argparse.html

Error message in the first example is outdated, may indicate further out of date information on page.

Example:

The tutorial says: prog.py: error: the following arguments are required: echo

When the actual error received is: prog.py: error: too few arguments

bitdancer commented 11 years ago

Actually it looks like it is future-dated. The documented error message is the one you get from 3.3. I guess someone backported a doc change for a feature change.

bitdancer commented 11 years ago

Ah, the whole tutorial is newish. So this is a bug just in the 2.7 version of the tutorial (it doesn't match the 2.7 code), and yes, there may be other issues as well.

bitdancer commented 11 years ago

See bpo-14034. Ezio apparently left the error messages unchanged on purpose...I'm not sure why.

ezio-melotti commented 11 years ago

When I backported the patch I probably didn't want to try all the examples to see what the py2 error was. In addition the py3 error is more clear even if it doesn't match what you actually get. I think this can be closed as won't fix, unless someone wants to propose a patch.

cf65f861-413d-442f-a4e8-82177d99568a commented 11 years ago

If it's okay, don't close this just yet. I'm new to this system but I'll submit a patch with any fixes to the tutorial I find.

terryjreedy commented 11 years ago

A quick patch would be 'This tutorial was written for argparse in Python 3. A few details are different in 2.x.' But feel free to do better.

ccda776a-4736-4dbd-bf35-88e58f6952ba commented 11 years ago

A quick patch would be 'This tutorial was written for argparse in Python 3. A few details are different in 2.x.' But feel free to do better.

That really sounds great, especially since it avoids resorting to things as ugly as "...and this is Python 2 output".

terryjreedy commented 9 years ago

Since the author of the tutorial agrees with my idea, and no one has come forward with anything else, I will make the change.

1762cc99-3127-4a62-9baf-30c3d0f51ef7 commented 9 years ago

New changeset e7428d7f641f by Terry Jan Reedy in branch '2.7': Issue bpo-16863: Explain difference between text and 2.7 behavior. https://hg.python.org/cpython/rev/e7428d7f641f

terryjreedy commented 9 years ago

Once this discrepancy is explained (3.x) prog.py: error: the following arguments are required: echo (2.7) prog.py: error: too few arguments I agree with leaving the 3.x version in the tutorial. A normal output discrepany might be a different matter.