You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SimpleArgumentParser().name will pass mypy checks, but will definitely throw error since argument is not there yet.
Meanwhile, in args = SimpleArgumentParser().parse_args(), args will still have irrelevant types information about the parser.
When trying to nest the subparser inside the main parser (Subparsers are not typed. #69), it make less sense for an unused subparser to be an accessible data. It will be harder to manipulate when methods mixed with data in the future.
SimpleArgument is just a built-in dataclass which can be instantiated normally, getting free hash and equal, free structural pattern matching, and can be tested like normal data.
Cleaner types interface.
Nested data types are natural.
An example of subparser:
importtapfromtapimportParser@dataclassclassFoo:
foo: str@dataclassclassBar:
bar: str@dataclassclassSimpleArgument:
name: strlanguage: str='Python'command: Parser[Foo|Bar]
args=tap.parse_args(SimpleArgument)
The text was updated successfully, but these errors were encountered:
Since making Tap, we've been hoping to find a way to separate the Namespace and ArgumentParser without making typing extremely unpleasant. We couldn't figure out a way to do it. This seems like a totally sensible proposal. We have to think more about this one, but we'll add it to our options in the design doc and update you with our thoughts.
Currently, parser class and the namespace object are the same type and object.
There're disadvantages doing this:
SimpleArgumentParser().name
will passmypy
checks, but will definitely throw error since argument is not there yet.Meanwhile, in
args = SimpleArgumentParser().parse_args()
,args
will still have irrelevant types information about the parser.Instead, we can have something like:
This is an improvement because:
SimpleArgument
is just a built-indataclass
which can be instantiated normally, getting free hash and equal, free structural pattern matching, and can be tested like normal data.An example of subparser:
The text was updated successfully, but these errors were encountered: