mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-07 20:54:28 +08:00
Use new union syntax in rest of stdlib (#5884)
This commit is contained in:
@@ -17,7 +17,6 @@ from typing import (
|
||||
Tuple,
|
||||
Type,
|
||||
TypeVar,
|
||||
Union,
|
||||
overload,
|
||||
)
|
||||
from typing_extensions import Literal
|
||||
@@ -64,33 +63,33 @@ class RawConfigParser(_parser):
|
||||
@overload
|
||||
def __init__(
|
||||
self,
|
||||
defaults: Optional[Mapping[str, Optional[str]]] = ...,
|
||||
defaults: Mapping[str, str | None] | None = ...,
|
||||
dict_type: Type[Mapping[str, str]] = ...,
|
||||
allow_no_value: Literal[True] = ...,
|
||||
*,
|
||||
delimiters: Sequence[str] = ...,
|
||||
comment_prefixes: Sequence[str] = ...,
|
||||
inline_comment_prefixes: Optional[Sequence[str]] = ...,
|
||||
inline_comment_prefixes: Sequence[str] | None = ...,
|
||||
strict: bool = ...,
|
||||
empty_lines_in_values: bool = ...,
|
||||
default_section: str = ...,
|
||||
interpolation: Optional[Interpolation] = ...,
|
||||
interpolation: Interpolation | None = ...,
|
||||
converters: _converters = ...,
|
||||
) -> None: ...
|
||||
@overload
|
||||
def __init__(
|
||||
self,
|
||||
defaults: Optional[_section] = ...,
|
||||
defaults: _section | None = ...,
|
||||
dict_type: Type[Mapping[str, str]] = ...,
|
||||
allow_no_value: bool = ...,
|
||||
*,
|
||||
delimiters: Sequence[str] = ...,
|
||||
comment_prefixes: Sequence[str] = ...,
|
||||
inline_comment_prefixes: Optional[Sequence[str]] = ...,
|
||||
inline_comment_prefixes: Sequence[str] | None = ...,
|
||||
strict: bool = ...,
|
||||
empty_lines_in_values: bool = ...,
|
||||
default_section: str = ...,
|
||||
interpolation: Optional[Interpolation] = ...,
|
||||
interpolation: Interpolation | None = ...,
|
||||
converters: _converters = ...,
|
||||
) -> None: ...
|
||||
def __len__(self) -> int: ...
|
||||
@@ -104,31 +103,31 @@ class RawConfigParser(_parser):
|
||||
def has_section(self, section: str) -> bool: ...
|
||||
def options(self, section: str) -> List[str]: ...
|
||||
def has_option(self, section: str, option: str) -> bool: ...
|
||||
def read(self, filenames: Union[_Path, Iterable[_Path]], encoding: Optional[str] = ...) -> List[str]: ...
|
||||
def read_file(self, f: Iterable[str], source: Optional[str] = ...) -> None: ...
|
||||
def read(self, filenames: _Path | Iterable[_Path], encoding: str | None = ...) -> List[str]: ...
|
||||
def read_file(self, f: Iterable[str], source: str | None = ...) -> None: ...
|
||||
def read_string(self, string: str, source: str = ...) -> None: ...
|
||||
def read_dict(self, dictionary: Mapping[str, Mapping[str, Any]], source: str = ...) -> None: ...
|
||||
def readfp(self, fp: Iterable[str], filename: Optional[str] = ...) -> None: ...
|
||||
def readfp(self, fp: Iterable[str], filename: str | None = ...) -> None: ...
|
||||
# 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: Optional[_section] = ...) -> 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: Optional[_section] = ..., fallback: _T = ...
|
||||
) -> Union[int, _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: Optional[_section] = ...) -> 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: Optional[_section] = ..., fallback: _T = ...
|
||||
) -> Union[float, _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: Optional[_section] = ...) -> 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: Optional[_section] = ..., fallback: _T = ...
|
||||
) -> Union[bool, _T]: ...
|
||||
self, section: str, option: str, *, raw: bool = ..., vars: _section | None = ..., fallback: _T = ...
|
||||
) -> bool | _T: ...
|
||||
def _get_conv(
|
||||
self,
|
||||
section: str,
|
||||
@@ -136,21 +135,19 @@ class RawConfigParser(_parser):
|
||||
conv: Callable[[str], _T],
|
||||
*,
|
||||
raw: bool = ...,
|
||||
vars: Optional[_section] = ...,
|
||||
vars: _section | None = ...,
|
||||
fallback: _T = ...,
|
||||
) -> _T: ...
|
||||
# This is incompatible with MutableMapping so we ignore the type
|
||||
@overload # type: ignore
|
||||
def get(self, section: str, option: str, *, raw: bool = ..., vars: Optional[_section] = ...) -> 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: Optional[_section] = ..., fallback: _T
|
||||
) -> Union[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: Optional[_section] = ...) -> AbstractSet[Tuple[str, SectionProxy]]: ...
|
||||
def items(self, *, raw: bool = ..., vars: _section | None = ...) -> AbstractSet[Tuple[str, SectionProxy]]: ...
|
||||
@overload
|
||||
def items(self, section: str, raw: bool = ..., vars: Optional[_section] = ...) -> List[Tuple[str, str]]: ...
|
||||
def set(self, section: str, option: str, value: Optional[str] = ...) -> None: ...
|
||||
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: ...
|
||||
def remove_section(self, section: str) -> bool: ...
|
||||
@@ -171,25 +168,21 @@ class SectionProxy(MutableMapping[str, str]):
|
||||
def parser(self) -> RawConfigParser: ...
|
||||
@property
|
||||
def name(self) -> str: ...
|
||||
def get(self, option: str, fallback: Optional[str] = ..., *, raw: bool = ..., vars: Optional[_section] = ..., _impl: Optional[Any] = ..., **kwargs: Any) -> str: ... # type: ignore
|
||||
def get(self, option: str, fallback: str | None = ..., *, raw: bool = ..., vars: _section | None = ..., _impl: Any | None = ..., **kwargs: Any) -> str: ... # type: ignore
|
||||
# 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: Optional[_section] = ...) -> int: ...
|
||||
def getint(self, option: str, *, raw: bool = ..., vars: _section | None = ...) -> int: ...
|
||||
@overload
|
||||
def getint(self, option: str, fallback: _T = ..., *, raw: bool = ..., vars: Optional[_section] = ...) -> Union[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: Optional[_section] = ...) -> float: ...
|
||||
def getfloat(self, option: str, *, raw: bool = ..., vars: _section | None = ...) -> float: ...
|
||||
@overload
|
||||
def getfloat(
|
||||
self, option: str, fallback: _T = ..., *, raw: bool = ..., vars: Optional[_section] = ...
|
||||
) -> Union[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: Optional[_section] = ...) -> bool: ...
|
||||
def getboolean(self, option: str, *, raw: bool = ..., vars: _section | None = ...) -> bool: ...
|
||||
@overload
|
||||
def getboolean(
|
||||
self, option: str, fallback: _T = ..., *, raw: bool = ..., vars: Optional[_section] = ...
|
||||
) -> Union[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]: ...
|
||||
|
||||
@@ -197,7 +190,7 @@ class ConverterMapping(MutableMapping[str, Optional[_converter]]):
|
||||
GETTERCRE: Pattern[Any]
|
||||
def __init__(self, parser: RawConfigParser) -> None: ...
|
||||
def __getitem__(self, key: str) -> _converter: ...
|
||||
def __setitem__(self, key: str, value: Optional[_converter]) -> None: ...
|
||||
def __setitem__(self, key: str, value: _converter | None) -> None: ...
|
||||
def __delitem__(self, key: str) -> None: ...
|
||||
def __iter__(self) -> Iterator[str]: ...
|
||||
def __len__(self) -> int: ...
|
||||
@@ -212,16 +205,16 @@ class NoSectionError(Error):
|
||||
|
||||
class DuplicateSectionError(Error):
|
||||
section: str
|
||||
source: Optional[str]
|
||||
lineno: Optional[int]
|
||||
def __init__(self, section: str, source: Optional[str] = ..., lineno: Optional[int] = ...) -> None: ...
|
||||
source: str | None
|
||||
lineno: int | None
|
||||
def __init__(self, section: str, source: str | None = ..., lineno: int | None = ...) -> None: ...
|
||||
|
||||
class DuplicateOptionError(Error):
|
||||
section: str
|
||||
option: str
|
||||
source: Optional[str]
|
||||
lineno: Optional[int]
|
||||
def __init__(self, section: str, option: str, source: Optional[str] = ..., lineno: Optional[int] = ...) -> None: ...
|
||||
source: str | None
|
||||
lineno: int | None
|
||||
def __init__(self, section: str, option: str, source: str | None = ..., lineno: int | None = ...) -> None: ...
|
||||
|
||||
class NoOptionError(Error):
|
||||
section: str
|
||||
@@ -245,7 +238,7 @@ class InterpolationSyntaxError(InterpolationError): ...
|
||||
class ParsingError(Error):
|
||||
source: str
|
||||
errors: List[Tuple[int, str]]
|
||||
def __init__(self, source: Optional[str] = ..., filename: Optional[str] = ...) -> None: ...
|
||||
def __init__(self, source: str | None = ..., filename: str | None = ...) -> None: ...
|
||||
def append(self, lineno: int, line: str) -> None: ...
|
||||
|
||||
class MissingSectionHeaderError(ParsingError):
|
||||
|
||||
Reference in New Issue
Block a user