GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Argparse: certain action types dont accept `metavar`, but should? · Issue #109792 · python/cpython Closed Labels pendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is providedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement DescriptionFeature or enhancementProposal:Given some arbitrary argument with a Unfortunately, you aren't allowed to supply The superclasses of all three do accept metavar, but in usercode i can just subclass them like so: class _HelpAction(argparse._HelpAction): def __init__(self, metavar=None, **kwargs): self.metavar = metavar super().__init__(**kwargs) class _StoreTrueAction(argparse._StoreTrueAction): def __init__(self, metavar=None, **kwargs): self.metavar = metavar super().__init__(**kwargs) class _StoreFalseAction(argparse._StoreFalseAction): def __init__(self, metavar=None, **kwargs): self.metavar = metavar super().__init__(**kwargs) class ArgumentParser(argparse.ArgumentParser): def __init__(self, *args, **kwargs): self.register("action", "store_true", _StoreTrueAction) self.register("action", "store_false", _StoreFalseAction) With no other changes, the rendered helptext names of the options properly accept and render the Some context/justification for why this is meaningful. I am currently using this snippet from the internet to, with relatively little effort, "properly" parse multiply nested subparsers in a way that maintains the nested relationship of the input args when they're written: class Nestedspace(argparse.Namespace): def __setattr__(self, name, value): if "." in name: group, name = name.split(".", 1) ns = getattr(self, group, Nestedspace()) setattr(ns, name, value) self.__dict__[group] = ns else: self.__dict__[name] = value Which produces This strategy requires setting the Having done that, you end up with Has this already been discussed elsewhere?This is a minor feature, which does not need previous discussion elsewhere Links to previous discussion of this feature:I dont know whether this is relevant to issues like #103678, where they're removing metavar from not-these-classes-but-boolean-action-option, which naively seems related. perhaps it's unrelated though. if it were just a matter of making the in-repo equivalents to these changes (plus tests), i'd be willing to contribue them, but i figured it might be this was for a reason, and wanted to make sure it'd be accepted before submitting a PR Activity
MetadataMetadataAssigneesLabelspendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is providedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement Projects
MilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |