Skip to content

Commit 98c6bf8

Browse files
authored
argparse: allow passing a callable to ArgumentParser (#3821)
Fixes #3806
1 parent e2a4092 commit 98c6bf8

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

stdlib/2and3/argparse.pyi

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import (
22
Any, Callable, Dict, Generator, Iterable, List, IO, NoReturn, Optional,
3-
Pattern, Sequence, Text, Tuple, Type, Union, TypeVar, overload
3+
Pattern, Protocol, Sequence, Text, Tuple, Type, Union, TypeVar, overload
44
)
55
import sys
66

@@ -77,11 +77,14 @@ class _ActionsContainer:
7777
def _handle_conflict_error(self, action: Action, conflicting_actions: Iterable[Tuple[Text, Action]]) -> NoReturn: ...
7878
def _handle_conflict_resolve(self, action: Action, conflicting_actions: Iterable[Tuple[Text, Action]]) -> None: ...
7979

80+
class _FormatterClass(Protocol):
81+
def __call__(self, prog: str) -> HelpFormatter: ...
82+
8083
class ArgumentParser(_AttributeHolder, _ActionsContainer):
8184
prog: _Text
8285
usage: Optional[_Text]
8386
epilog: Optional[_Text]
84-
formatter_class: Type[HelpFormatter]
87+
formatter_class: _FormatterClass
8588
fromfile_prefix_chars: Optional[_Text]
8689
add_help: bool
8790

@@ -100,7 +103,7 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
100103
description: Optional[str] = ...,
101104
epilog: Optional[str] = ...,
102105
parents: Sequence[ArgumentParser] = ...,
103-
formatter_class: Type[HelpFormatter] = ...,
106+
formatter_class: _FormatterClass = ...,
104107
prefix_chars: str = ...,
105108
fromfile_prefix_chars: Optional[str] = ...,
106109
argument_default: Optional[str] = ...,
@@ -114,7 +117,7 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
114117
description: Optional[Text] = ...,
115118
epilog: Optional[Text] = ...,
116119
parents: Sequence[ArgumentParser] = ...,
117-
formatter_class: Type[HelpFormatter] = ...,
120+
formatter_class: _FormatterClass = ...,
118121
prefix_chars: Text = ...,
119122
fromfile_prefix_chars: Optional[Text] = ...,
120123
argument_default: Optional[Text] = ...,

0 commit comments

Comments
 (0)