Comments (8)
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.
That will probably not happen before a couple of weeks in all likelihood, due to #107 (comment).
from defopt.
@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.
OK, pushed the patch.
from defopt.
Thank you @anntzer ! I will look for the new release on pypi/conda
from defopt.
Hi @anntzer following up here - is there a plan to include this change in a pypi release?
from defopt.
Done :) Thanks for the ping.
from defopt.
Done :) Thanks for the ping.
Sweet! Thanks again :)
from defopt.
Related Issues (20)
- feature request: better support for options that take multiple arguments and have a default HOT 2
- feature request: support "count" action HOT 2
- Documented strong compatibility guarantees HOT 2
- Add a registry class HOT 4
- Consume command line arguments in 2 function calls HOT 10
- Support URLs in docstring
- Reject duplicate options for a single parameter rather than silently dropping one HOT 2
- Any way to indent within tool help text without runtime / linting error? HOT 1
- Add support for datetime.date and datetime.datetime parsers HOT 5
- Argument name suffixes as workaround for name collisions HOT 4
- Should `Optional[Tuple[type1]]` be supported HOT 7
- PyInstaller, Nuitka compatibility? HOT 5
- pin setuptools_scm < 6.4 to support python3.6 HOT 2
- Consume command line arguments in 2 calls - help text has only one call's parameters HOT 17
- Using keyword only dataclass with `defopt.run` gives a docutils warning HOT 1
- py.typed file? HOT 3
- NotImplementedError: <class 'defopt._parse_docstring.<locals>.Visitor'> visiting unknown node type: definition_list HOT 3
- TypeError: can only join an iterable HOT 2
- Feature Request: Make Optional[bool] still act as a flag HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from defopt.