1- from collections .abc import Callable , Container , Hashable , Iterable , Mapping
1+ from collections .abc import Callable , Container , Hashable , Iterable
22from io import TextIOWrapper
33from re import Pattern
4- from typing import Any , Final , TextIO , TypeVar
4+ from typing import Any , Final , Protocol , TypeVar , type_check_only
55
66_T = TypeVar ("_T" )
77_H = TypeVar ("_H" , bound = Hashable )
@@ -14,16 +14,22 @@ xml_decl_re: Final[Pattern[str]]
1414class ClassNotFound (ValueError ): ...
1515class OptionError (Exception ): ...
1616
17+ @type_check_only
18+ class _SupportsGetStrWithDefault (Protocol ):
19+ def get (self , item : str , default : Any , / ) -> Any : ...
20+
1721# 'options' contains the **kwargs of an arbitrary function.
1822def get_choice_opt (
19- options : Mapping [ str , Any ] , optname : str , allowed : Container [_T ], default : _T | None = None , normcase : bool = False
23+ options : _SupportsGetStrWithDefault , optname : str , allowed : Container [_T ], default : _T | None = None , normcase : bool = False
2024) -> _T : ...
21- def get_bool_opt (options : Mapping [ str , Any ] , optname : str , default : bool | None = None ) -> bool : ...
22- def get_int_opt (options : Mapping [ str , Any ] , optname : str , default : int | None = None ) -> int : ...
25+ def get_bool_opt (options : _SupportsGetStrWithDefault , optname : str , default : bool | None = None ) -> bool : ...
26+ def get_int_opt (options : _SupportsGetStrWithDefault , optname : str , default : int | None = None ) -> int : ...
2327
2428# Return type and type of 'default' depend on the signature of the function whose **kwargs
2529# are being processed.
26- def get_list_opt (options : Mapping [str , Any ], optname : str , default : list [Any ] | tuple [Any , ...] | None = None ) -> list [Any ]: ...
30+ def get_list_opt (
31+ options : _SupportsGetStrWithDefault , optname : str , default : list [Any ] | tuple [Any , ...] | None = None
32+ ) -> list [Any ]: ...
2733def docstring_headline (obj : object ) -> str : ...
2834def make_analysator (f : Callable [[str ], float ]) -> Callable [[str ], float ]: ...
2935def shebang_matches (text : str , regex : str ) -> bool : ...
@@ -38,8 +44,10 @@ class Future:
3844 def get (self ) -> None : ...
3945
4046def guess_decode (text : bytes ) -> tuple [str , str ]: ...
41- def guess_decode_from_terminal (text : bytes , term : TextIO ) -> tuple [str , str ]: ...
42- def terminal_encoding (term : TextIO ) -> str : ...
47+
48+ # If 'term' has an 'encoding' attribute, it should be a str. Otherwise any object is accepted.
49+ def guess_decode_from_terminal (text : bytes , term : Any ) -> tuple [str , str ]: ...
50+ def terminal_encoding (term : Any ) -> str : ...
4351
4452class UnclosingTextIOWrapper (TextIOWrapper ):
4553 def close (self ) -> None : ...
0 commit comments