11from collections .abc import Iterable , Mapping
2+ from getopt import _SliceableT , _StrSequenceT_co
23from re import Pattern
34from typing import Any , Final , overload
45from typing_extensions import TypeAlias
56
67_Option : TypeAlias = tuple [str , str | None , str ]
7- _GR : TypeAlias = tuple [list [str ], OptionDummy ]
88
99longopt_pat : Final = r"[a-zA-Z](?:[a-zA-Z0-9-]*)"
1010longopt_re : Final [Pattern [str ]]
@@ -15,15 +15,25 @@ class FancyGetopt:
1515 def __init__ (self , option_table : list [_Option ] | None = None ) -> None : ...
1616 # TODO kinda wrong, `getopt(object=object())` is invalid
1717 @overload
18- def getopt (self , args : list [str ] | None = None ) -> _GR : ...
18+ def getopt (
19+ self , args : _SliceableT [_StrSequenceT_co ] | None = None , object : None = None
20+ ) -> tuple [_StrSequenceT_co , OptionDummy ]: ...
1921 @overload
20- def getopt (self , args : list [str ] | None , object : Any ) -> list [str ]: ...
22+ def getopt (
23+ self , args : _SliceableT [_StrSequenceT_co ] | None , object : Any
24+ ) -> _StrSequenceT_co : ... # object is an arbitrary non-slotted object
2125 def get_option_order (self ) -> list [tuple [str , str ]]: ...
2226 def generate_help (self , header : str | None = None ) -> list [str ]: ...
2327
28+ # Same note as FancyGetopt.getopt
29+ @overload
2430def fancy_getopt (
25- options : list [_Option ], negative_opt : Mapping [_Option , _Option ], object : Any , args : list [str ] | None
26- ) -> list [str ] | _GR : ...
31+ options : list [_Option ], negative_opt : Mapping [_Option , _Option ], object : None , args : _SliceableT [_StrSequenceT_co ] | None
32+ ) -> tuple [_StrSequenceT_co , OptionDummy ]: ...
33+ @overload
34+ def fancy_getopt (
35+ options : list [_Option ], negative_opt : Mapping [_Option , _Option ], object : Any , args : _SliceableT [_StrSequenceT_co ] | None
36+ ) -> _StrSequenceT_co : ...
2737
2838WS_TRANS : Final [dict [int , str ]]
2939
0 commit comments