mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-07-12 03:10:52 +08:00
Allow any sliceable sequence as getopt args (#13116)
This commit is contained in:
+15
-3
@@ -1,10 +1,22 @@
|
||||
from collections.abc import Iterable
|
||||
from collections.abc import Iterable, Sequence
|
||||
from typing import Protocol, TypeVar, overload, type_check_only
|
||||
|
||||
_StrSequenceT_co = TypeVar("_StrSequenceT_co", covariant=True, bound=Sequence[str])
|
||||
|
||||
@type_check_only
|
||||
class _SliceableT(Protocol[_StrSequenceT_co]):
|
||||
@overload
|
||||
def __getitem__(self, key: int, /) -> str: ...
|
||||
@overload
|
||||
def __getitem__(self, key: slice, /) -> _StrSequenceT_co: ...
|
||||
|
||||
__all__ = ["GetoptError", "error", "getopt", "gnu_getopt"]
|
||||
|
||||
def getopt(args: list[str], shortopts: str, longopts: Iterable[str] | str = []) -> tuple[list[tuple[str, str]], list[str]]: ...
|
||||
def getopt(
|
||||
args: _SliceableT[_StrSequenceT_co], shortopts: str, longopts: Iterable[str] | str = []
|
||||
) -> tuple[list[tuple[str, str]], _StrSequenceT_co]: ...
|
||||
def gnu_getopt(
|
||||
args: list[str], shortopts: str, longopts: Iterable[str] | str = []
|
||||
args: Sequence[str], shortopts: str, longopts: Iterable[str] | str = []
|
||||
) -> tuple[list[tuple[str, str]], list[str]]: ...
|
||||
|
||||
class GetoptError(Exception):
|
||||
|
||||
Reference in New Issue
Block a user