mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-01-01 00:53:23 +08:00
[optparse] Change Uses of List[] to Sequence[] in argument positions. (#1179)
* Change Uses of List[] to Sequence[] in argument positions. One of these (parse_args()) broke in real-world code, because the expected type was List[Union[str, bytes]] but the actual type was List[str] (because List is invariant). That is ridiculous, so I changed the accepted type to Sequence[_Text] which is covariant. Then I found a few other methods/functions that probably should also be changed to Sequence, but I'm less certain of those. I'm not at all sure about the instance/class attributes, so I left those alone (though I suspect those might also have to switch). * Fixes suggested by code review - Changed Sequence[Option] to Iterable[Option] everywhere - Changed _process_args to plain List
This commit is contained in:
committed by
Jelle Zijlstra
parent
6e1d915944
commit
a934d57f3b
@@ -1,6 +1,6 @@
|
||||
# Generated by pytype, with only minor tweaks. Might be incomplete.
|
||||
import sys
|
||||
from typing import Any, Optional, List, Callable, Tuple, Dict, Iterable, Union, Mapping, IO
|
||||
from typing import Any, Callable, Dict, IO, Iterable, List, Mapping, Optional, Sequence, Tuple, Union
|
||||
|
||||
# See https://groups.google.com/forum/#!topic/python-ideas/gA1gdj3RZ5g
|
||||
if sys.version_info >= (3,):
|
||||
@@ -27,7 +27,7 @@ class BadOptionError(OptParseError):
|
||||
|
||||
class AmbiguousOptionError(BadOptionError):
|
||||
possibilities = ... # type: Iterable[_Text]
|
||||
def __init__(self, opt_str: _Text, possibilities: List[_Text]) -> None: ...
|
||||
def __init__(self, opt_str: _Text, possibilities: Sequence[_Text]) -> None: ...
|
||||
|
||||
class OptionError(OptParseError):
|
||||
msg = ... # type: _Text
|
||||
@@ -136,7 +136,7 @@ class OptionContainer:
|
||||
def _create_option_mappings(self) -> None: ...
|
||||
def _share_option_mappings(self, parser: OptionParser) -> None: ...
|
||||
def add_option(self, *args, **kwargs) -> Any: ...
|
||||
def add_options(self, option_list: List[Option]) -> None: ...
|
||||
def add_options(self, option_list: Iterable[Option]) -> None: ...
|
||||
def destroy(self) -> None: ...
|
||||
def format_description(self, formatter: Optional[HelpFormatter]) -> Any: ...
|
||||
def format_help(self, formatter: Optional[HelpFormatter]) -> _Text: ...
|
||||
@@ -171,7 +171,7 @@ class OptionParser(OptionContainer):
|
||||
values = ... # type: Any
|
||||
version = ... # type: _Text
|
||||
def __init__(self, usage: Optional[_Text] = ...,
|
||||
option_list: List[Option] = ...,
|
||||
option_list: Iterable[Option] = ...,
|
||||
option_class: Option = ...,
|
||||
version: Optional[_Text] = ...,
|
||||
conflict_handler: _Text = ...,
|
||||
@@ -187,8 +187,8 @@ class OptionParser(OptionContainer):
|
||||
def _get_args(self, args: Iterable) -> List[Any]: ...
|
||||
def _init_parsing_state(self) -> None: ...
|
||||
def _match_long_opt(self, opt: _Text) -> _Text: ...
|
||||
def _populate_option_list(self, option_list: List[Option], add_help: bool = ...) -> None: ...
|
||||
def _process_args(self, largs: List[_Text], rargs: List, values: Values) -> None: ...
|
||||
def _populate_option_list(self, option_list: Iterable[Option], add_help: bool = ...) -> None: ...
|
||||
def _process_args(self, largs: List, rargs: List, values: Values) -> None: ...
|
||||
def _process_long_opt(self, rargs: List, values: Any) -> None: ...
|
||||
def _process_short_opts(self, rargs: List, values: Any) -> None: ...
|
||||
def add_option_group(self, *args, **kwargs) -> OptionParser: ...
|
||||
@@ -206,7 +206,7 @@ class OptionParser(OptionContainer):
|
||||
def get_prog_name(self) -> _Text: ...
|
||||
def get_usage(self) -> _Text: ...
|
||||
def get_version(self) -> _Text: ...
|
||||
def parse_args(self, args: Optional[List[_Text]] = ..., values: Optional[Values] = ...) -> Tuple[Any, ...]: ...
|
||||
def parse_args(self, args: Optional[Sequence[_Text]] = ..., values: Optional[Values] = ...) -> Tuple[Any, ...]: ...
|
||||
def print_usage(self, file: Optional[IO[str]] = ...) -> None: ...
|
||||
def print_help(self, file: Optional[IO[str]] = ...) -> None: ...
|
||||
def print_version(self, file: Optional[IO[str]] = ...) -> None: ...
|
||||
|
||||
Reference in New Issue
Block a user