Skip to content
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

optparse quirks #48528

Closed
kbriggs mannequin opened this issue Nov 7, 2008 · 4 comments
Closed

optparse quirks #48528

kbriggs mannequin opened this issue Nov 7, 2008 · 4 comments
Labels
extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error

Comments

@kbriggs
Copy link
Mannequin

kbriggs mannequin commented Nov 7, 2008

BPO 4278
Nosy @loewis, @amauryfa, @agbuckley

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:

assignee = None
closed_at = <Date 2009-07-01.16:53:00.456>
created_at = <Date 2008-11-07.13:13:39.832>
labels = ['extension-modules', 'type-bug']
title = 'optparse quirks'
updated_at = <Date 2009-07-01.16:53:00.449>
user = 'https://bugs.python.org/kbriggs'

bugs.python.org fields:

activity = <Date 2009-07-01.16:53:00.449>
actor = 'amaury.forgeotdarc'
assignee = 'none'
closed = True
closed_date = <Date 2009-07-01.16:53:00.456>
closer = 'amaury.forgeotdarc'
components = ['Extension Modules']
creation = <Date 2008-11-07.13:13:39.832>
creator = 'kbriggs'
dependencies = []
files = []
hgrepos = []
issue_num = 4278
keywords = []
message_count = 4.0
messages = ['75602', '77499', '82753', '89990']
nosy_count = 4.0
nosy_names = ['loewis', 'amaury.forgeotdarc', 'kbriggs', 'andybuckley']
pr_nums = []
priority = 'normal'
resolution = 'works for me'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue4278'
versions = ['Python 2.7']

@kbriggs
Copy link
Mannequin Author

kbriggs mannequin commented Nov 7, 2008

I got the message:

optparse.OptionError: invalid long option string '-T0': must start with
--, followed by non-dash

This is bad - the real error was that I gave a short option which did
not have a single letter.

Also, it seems that add_option('--height-of-plot','-h') is not allowed,
because -h can only go with --help. How do I override this?

Keith

@kbriggs kbriggs mannequin added extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error labels Nov 7, 2008
@loewis
Copy link
Mannequin

loewis mannequin commented Dec 10, 2008

No patch proposed yet, so retargetting to trunk.

@agbuckley
Copy link
Mannequin

agbuckley mannequin commented Feb 26, 2009

Are these really bugs? The first message just reports the error the
other way around from how you view it: you are thinking of "-TO" as a
two-character "short option", optparse thinks of it as a two-character
long option which is missing a dash. I would side with optparse's
definition, since the point of short options is that they can be
combined under a single dash --- a multi-character option can't do that,
and so can't be "short" by definition.

In both this and the "-h" issue, optparse is reasonably enforcing a UI
convention as well as providing parsing facilities. That uniformity of
UI behaviour is a design goal is made explicit in the documentation.
Using optparse means that users can rely on "-h" to give them help
documentation, which IMO is a very useful convention to respect. And the
splitting of long and short options by whether they are single character
(and hence can be combined) or multi-character (hence uncombinable, but
good for less-used options without eating up the alphabetic option
namespace) is another nice convention which optparse enforces.

-1 from me: I think the existing behaviours are good, largely *because*
they aren't flexible.

@amauryfa
Copy link
Member

amauryfa commented Jul 1, 2009

  • For the -h option, you may add "add_help_option=False" when creating
    the Optparse object

  • concerning the error message: every parser that tries to give
    meaningful error messages has to guess what the user really meant. The
    exact text is really an implementation detail.

@amauryfa amauryfa closed this as completed Jul 1, 2009
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant