-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Issue with function to customize argparse formatter class #8487
Comments
This issue should be moved to typeshed (which defines the signature for |
@hauntsaninja, @srittau, I have one question: if the formatter_class=argparse.RawDescriptionHelpFormatter |
@lucatrv Actually, a class is a callable as well, with parameters equal to the parameters of it's |
This has been fixed in python/typeshed#3821 by @hauntsaninja. |
I ran into this yesterday when subclassing an class ArgumentParser(argparse.ArgumentParser):
def __init__( # pylint: disable=too-many-arguments
self,
...
formatter_class: Optional[Type[argparse.HelpFormatter]] = None,
...
) -> None:
...
if formatter_class is None:
formatter_class = argparse.RawTextHelpFormatter
super().__init__(
name, usage, description, epilog, parents,
formatter_class, DEFAULT_PREFIX, fromfile_prefix_chars,
argument_default, conflict_handler, False, allow_abbrev
) Produces: |
formater_class seems to be a typeshed bug, see python/mypy#8487 (comment) we're just going to ignore it for now, since it works.
I'm using mypy 0.761 with Python 3.8.2 on Windows.
The suggested way to customize the argparse formatter class to control text width is to use a lambda function, as follows:
but with that code mypy emits the following error:
I could not find any workaround, the only solution is to avoid a function and redefine the formatter class.
See example and discussion.
The text was updated successfully, but these errors were encountered: