From abea36c06960a515609f0b889ae5c630a39fd961 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Thu, 7 Jul 2022 16:17:09 +0100 Subject: [PATCH] Improve `configparser` alias names (#8254) --- stdlib/configparser.pyi | 75 ++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 38 deletions(-) diff --git a/stdlib/configparser.pyi b/stdlib/configparser.pyi index 5ffac353a..96145f48c 100644 --- a/stdlib/configparser.pyi +++ b/stdlib/configparser.pyi @@ -28,11 +28,10 @@ __all__ = [ "MAX_INTERPOLATION_DEPTH", ] -# Internal type aliases -_section: TypeAlias = Mapping[str, str] -_parser: TypeAlias = MutableMapping[str, _section] -_converter: TypeAlias = Callable[[str], Any] -_converters: TypeAlias = dict[str, _converter] +_Section: TypeAlias = Mapping[str, str] +_Parser: TypeAlias = MutableMapping[str, _Section] +_ConverterCallback: TypeAlias = Callable[[str], Any] +_ConvertersMap: TypeAlias = dict[str, _ConverterCallback] _T = TypeVar("_T") if sys.version_info >= (3, 7): @@ -44,18 +43,18 @@ DEFAULTSECT: Literal["DEFAULT"] MAX_INTERPOLATION_DEPTH: Literal[10] class Interpolation: - def before_get(self, parser: _parser, section: str, option: str, value: str, defaults: _section) -> str: ... - def before_set(self, parser: _parser, section: str, option: str, value: str) -> str: ... - def before_read(self, parser: _parser, section: str, option: str, value: str) -> str: ... - def before_write(self, parser: _parser, section: str, option: str, value: str) -> str: ... + def before_get(self, parser: _Parser, section: str, option: str, value: str, defaults: _Section) -> str: ... + def before_set(self, parser: _Parser, section: str, option: str, value: str) -> str: ... + def before_read(self, parser: _Parser, section: str, option: str, value: str) -> str: ... + def before_write(self, parser: _Parser, section: str, option: str, value: str) -> str: ... class BasicInterpolation(Interpolation): ... class ExtendedInterpolation(Interpolation): ... class LegacyInterpolation(Interpolation): - def before_get(self, parser: _parser, section: str, option: str, value: str, vars: _section) -> str: ... + def before_get(self, parser: _Parser, section: str, option: str, value: str, vars: _Section) -> str: ... -class RawConfigParser(_parser): +class RawConfigParser(_Parser): _SECT_TMPL: ClassVar[str] # undocumented _OPT_TMPL: ClassVar[str] # undocumented _OPT_NV_TMPL: ClassVar[str] # undocumented @@ -81,12 +80,12 @@ class RawConfigParser(_parser): empty_lines_in_values: bool = ..., default_section: str = ..., interpolation: Interpolation | None = ..., - converters: _converters = ..., + converters: _ConvertersMap = ..., ) -> None: ... @overload def __init__( self, - defaults: _section | None = ..., + defaults: _Section | None = ..., dict_type: type[Mapping[str, str]] = ..., allow_no_value: bool = ..., *, @@ -97,15 +96,15 @@ class RawConfigParser(_parser): empty_lines_in_values: bool = ..., default_section: str = ..., interpolation: Interpolation | None = ..., - converters: _converters = ..., + converters: _ConvertersMap = ..., ) -> None: ... def __len__(self) -> int: ... def __getitem__(self, key: str) -> SectionProxy: ... - def __setitem__(self, key: str, value: _section) -> None: ... + def __setitem__(self, key: str, value: _Section) -> None: ... def __delitem__(self, key: str) -> None: ... def __iter__(self) -> Iterator[str]: ... def __contains__(self, key: object) -> bool: ... - def defaults(self) -> _section: ... + def defaults(self) -> _Section: ... def sections(self) -> list[str]: ... def add_section(self, section: str) -> None: ... def has_section(self, section: str) -> bool: ... @@ -119,22 +118,22 @@ class RawConfigParser(_parser): # These get* methods are partially applied (with the same names) in # SectionProxy; the stubs should be kept updated together @overload - def getint(self, section: str, option: str, *, raw: bool = ..., vars: _section | None = ...) -> int: ... + def getint(self, section: str, option: str, *, raw: bool = ..., vars: _Section | None = ...) -> int: ... @overload def getint( - self, section: str, option: str, *, raw: bool = ..., vars: _section | None = ..., fallback: _T = ... + self, section: str, option: str, *, raw: bool = ..., vars: _Section | None = ..., fallback: _T = ... ) -> int | _T: ... @overload - def getfloat(self, section: str, option: str, *, raw: bool = ..., vars: _section | None = ...) -> float: ... + def getfloat(self, section: str, option: str, *, raw: bool = ..., vars: _Section | None = ...) -> float: ... @overload def getfloat( - self, section: str, option: str, *, raw: bool = ..., vars: _section | None = ..., fallback: _T = ... + self, section: str, option: str, *, raw: bool = ..., vars: _Section | None = ..., fallback: _T = ... ) -> float | _T: ... @overload - def getboolean(self, section: str, option: str, *, raw: bool = ..., vars: _section | None = ...) -> bool: ... + def getboolean(self, section: str, option: str, *, raw: bool = ..., vars: _Section | None = ...) -> bool: ... @overload def getboolean( - self, section: str, option: str, *, raw: bool = ..., vars: _section | None = ..., fallback: _T = ... + self, section: str, option: str, *, raw: bool = ..., vars: _Section | None = ..., fallback: _T = ... ) -> bool | _T: ... def _get_conv( self, @@ -143,18 +142,18 @@ class RawConfigParser(_parser): conv: Callable[[str], _T], *, raw: bool = ..., - vars: _section | None = ..., + vars: _Section | None = ..., fallback: _T = ..., ) -> _T: ... # This is incompatible with MutableMapping so we ignore the type @overload # type: ignore[override] - def get(self, section: str, option: str, *, raw: bool = ..., vars: _section | None = ...) -> str: ... + def get(self, section: str, option: str, *, raw: bool = ..., vars: _Section | None = ...) -> str: ... @overload - def get(self, section: str, option: str, *, raw: bool = ..., vars: _section | None = ..., fallback: _T) -> str | _T: ... + def get(self, section: str, option: str, *, raw: bool = ..., vars: _Section | None = ..., fallback: _T) -> str | _T: ... @overload - def items(self, *, raw: bool = ..., vars: _section | None = ...) -> ItemsView[str, SectionProxy]: ... + def items(self, *, raw: bool = ..., vars: _Section | None = ...) -> ItemsView[str, SectionProxy]: ... @overload - def items(self, section: str, raw: bool = ..., vars: _section | None = ...) -> list[tuple[str, str]]: ... + def items(self, section: str, raw: bool = ..., vars: _Section | None = ...) -> list[tuple[str, str]]: ... def set(self, section: str, option: str, value: str | None = ...) -> None: ... def write(self, fp: SupportsWrite[str], space_around_delimiters: bool = ...) -> None: ... def remove_option(self, section: str, option: str) -> bool: ... @@ -184,32 +183,32 @@ class SectionProxy(MutableMapping[str, str]): fallback: str | None = ..., *, raw: bool = ..., - vars: _section | None = ..., + vars: _Section | None = ..., _impl: Any | None = ..., **kwargs: Any, ) -> str: ... # These are partially-applied version of the methods with the same names in # RawConfigParser; the stubs should be kept updated together @overload - def getint(self, option: str, *, raw: bool = ..., vars: _section | None = ...) -> int: ... + def getint(self, option: str, *, raw: bool = ..., vars: _Section | None = ...) -> int: ... @overload - def getint(self, option: str, fallback: _T = ..., *, raw: bool = ..., vars: _section | None = ...) -> int | _T: ... + def getint(self, option: str, fallback: _T = ..., *, raw: bool = ..., vars: _Section | None = ...) -> int | _T: ... @overload - def getfloat(self, option: str, *, raw: bool = ..., vars: _section | None = ...) -> float: ... + def getfloat(self, option: str, *, raw: bool = ..., vars: _Section | None = ...) -> float: ... @overload - def getfloat(self, option: str, fallback: _T = ..., *, raw: bool = ..., vars: _section | None = ...) -> float | _T: ... + def getfloat(self, option: str, fallback: _T = ..., *, raw: bool = ..., vars: _Section | None = ...) -> float | _T: ... @overload - def getboolean(self, option: str, *, raw: bool = ..., vars: _section | None = ...) -> bool: ... + def getboolean(self, option: str, *, raw: bool = ..., vars: _Section | None = ...) -> bool: ... @overload - def getboolean(self, option: str, fallback: _T = ..., *, raw: bool = ..., vars: _section | None = ...) -> bool | _T: ... + def getboolean(self, option: str, fallback: _T = ..., *, raw: bool = ..., vars: _Section | None = ...) -> bool | _T: ... # SectionProxy can have arbitrary attributes when custom converters are used def __getattr__(self, key: str) -> Callable[..., Any]: ... -class ConverterMapping(MutableMapping[str, _converter | None]): - GETTERCRE: Pattern[Any] +class ConverterMapping(MutableMapping[str, _ConverterCallback | None]): + GETTERCRE: ClassVar[Pattern[Any]] def __init__(self, parser: RawConfigParser) -> None: ... - def __getitem__(self, key: str) -> _converter: ... - def __setitem__(self, key: str, value: _converter | None) -> None: ... + def __getitem__(self, key: str) -> _ConverterCallback: ... + def __setitem__(self, key: str, value: _ConverterCallback | None) -> None: ... def __delitem__(self, key: str) -> None: ... def __iter__(self) -> Iterator[str]: ... def __len__(self) -> int: ...