-
Notifications
You must be signed in to change notification settings - Fork 116
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
Changed with_argparser() and as_subcommand_to() to accept either an A… #1278
Conversation
Codecov ReportAll modified lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1278 +/- ##
=======================================
Coverage 98.55% 98.56%
=======================================
Files 22 22
Lines 5729 5768 +39
=======================================
+ Hits 5646 5685 +39
Misses 83 83
☔ View full report in Codecov by Sentry. |
039f92b
to
e68867d
Compare
cmd2/cmd2.py
Outdated
@@ -659,6 +668,43 @@ def register_command_set(self, cmdset: CommandSet) -> None: | |||
cmdset.on_unregistered() | |||
raise | |||
|
|||
def _build_parser(self, parent: Union['Cmd', CommandSet], parser_builder: Any) -> Optional[argparse.ArgumentParser]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parser_builder shouldn't be Optional[Union[argparse.ArgumentParser, Callable]] ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the point is to always result in an instance of a parser after this. either by deep-copying the provided one or calling the builder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh wait, misread your comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, this got messy because staticmethod
and classmethod
are not considered callable for some reason and there's some complicated mess where mypy wants to treat them like a generic type but at runtime this causes a python parsing error and fails..
3dec00d
to
744311b
Compare
…rgumentParser or a factory callable that returns an ArgumentParser. Changed Cmd constructor to construct an instance-specific ArgumentParser using either the factory callable or by deep-copying the provided ArgumentParser. With this change a new argparse instance should be created for each instance of Cmd. Addresses #1002
744311b
to
469876b
Compare
…rgumentParser or a
factory callable that returns an ArgumentParser.
Changed Cmd constructor to construct an instance-specific ArgumentParser using either the factory callable or by deep-copying the provided ArgumentParser.
With this change a new argparse instance should be created for each instance of Cmd.
Addresses #1002