Git Product home page Git Product logo

Comments (8)

anntzer avatar anntzer commented on September 2, 2024 1

Seems reasonable. Can you confirm that

diff --git i/lib/defopt.py w/lib/defopt.py
index 16898dc..a71e38f 100644
--- i/lib/defopt.py
+++ w/lib/defopt.py
@@ -491,7 +491,12 @@ def _populate_parser(func, parser, parsers, short, cli_options,
                 kwargs['action'] = 'append'
                 kwargs['default'] = _DefaultList()
         member_types = None
-        if _ti_get_origin(type_) is tuple:
+
+        if isinstance(type_, type) and issubclass(type_, Enum):
+            # Enums must be checked first to handle enums-of-namedtuples.
+            kwargs['type'] = _get_parser(type_, parsers)
+            kwargs['metavar'] = '{' + ','.join(type_.__members__) + '}'
+        elif _ti_get_origin(type_) is tuple:
             member_types = _ti_get_args(type_)
             # Variable-length tuples of homogenous type are specified like
             # Tuple[int, ...]
@@ -516,9 +521,7 @@ def _populate_parser(func, parser, parsers, short, cli_options,
                 kwargs['metavar'] = type_._fields
         else:
             kwargs['type'] = _get_parser(type_, parsers)
-            if isinstance(type_, type) and issubclass(type_, Enum):
-                kwargs['metavar'] = '{' + ','.join(type_.__members__) + '}'
-            elif _ti_get_origin(type_) is Literal:
+            if _ti_get_origin(type_) is Literal:
                 kwargs['metavar'] = (
                     '{' + ','.join(map(str, _ti_get_args(type_))) + '}')
         actions.append(_add_argument(parser, name, short, **kwargs))

fixes the issue for you?

from defopt.

anntzer avatar anntzer commented on September 2, 2024 1

That will probably not happen before a couple of weeks in all likelihood, due to #107 (comment).

from defopt.

Ben-Habermeyer avatar Ben-Habermeyer commented on September 2, 2024

@anntzer yes this looks right to me!

›› python test2.py -h                                                                                                           10:59 Mar14
6.3.0
usage: test.py [-h] -c {SMA,RHD}

print stuff

optional arguments:
  -h, --help            show this help message and exit
  -c {SMA,RHD}, --case {SMA,RHD}
                        special case

from defopt.

anntzer avatar anntzer commented on September 2, 2024

OK, pushed the patch.

from defopt.

Ben-Habermeyer avatar Ben-Habermeyer commented on September 2, 2024

Thank you @anntzer ! I will look for the new release on pypi/conda

from defopt.

Ben-Habermeyer avatar Ben-Habermeyer commented on September 2, 2024

Hi @anntzer following up here - is there a plan to include this change in a pypi release?

from defopt.

anntzer avatar anntzer commented on September 2, 2024

Done :) Thanks for the ping.

from defopt.

Ben-Habermeyer avatar Ben-Habermeyer commented on September 2, 2024

Done :) Thanks for the ping.

Sweet! Thanks again :)

from defopt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.