Switch to PEP-604 syntax in python2 stubs (#5915)

Signed-off-by: oleg.hoefling <oleg.hoefling@gmail.com>
This commit is contained in:
Oleg Höfling
2021-08-14 11:12:30 +02:00
committed by GitHub
parent 431c4f7fc1
commit ff63953188
235 changed files with 2473 additions and 2768 deletions

View File

@@ -9,17 +9,12 @@ Any = object()
class TypeVar:
__name__: str
__bound__: Optional[Type[Any]]
__bound__: Type[Any] | None
__constraints__: Tuple[Type[Any], ...]
__covariant__: bool
__contravariant__: bool
def __init__(
self,
name: str,
*constraints: Type[Any],
bound: Optional[Type[Any]] = ...,
covariant: bool = ...,
contravariant: bool = ...,
self, name: str, *constraints: Type[Any], bound: Type[Any] | None = ..., covariant: bool = ..., contravariant: bool = ...
) -> None: ...
_promote = object()
@@ -144,11 +139,11 @@ class Generator(Iterator[_T_co], Generic[_T_co, _T_contra, _V_co]):
@overload
@abstractmethod
def throw(
self, __typ: Type[BaseException], __val: Union[BaseException, object] = ..., __tb: Optional[TracebackType] = ...
self, __typ: Type[BaseException], __val: BaseException | object = ..., __tb: TracebackType | None = ...
) -> _T_co: ...
@overload
@abstractmethod
def throw(self, __typ: BaseException, __val: None = ..., __tb: Optional[TracebackType] = ...) -> _T_co: ...
def throw(self, __typ: BaseException, __val: None = ..., __tb: TracebackType | None = ...) -> _T_co: ...
@abstractmethod
def close(self) -> None: ...
@property
@@ -218,9 +213,9 @@ class AbstractSet(Iterable[_T_co], Container[_T_co], Generic[_T_co]):
def __gt__(self, s: AbstractSet[Any]) -> bool: ...
def __ge__(self, s: AbstractSet[Any]) -> bool: ...
def __and__(self, s: AbstractSet[Any]) -> AbstractSet[_T_co]: ...
def __or__(self, s: AbstractSet[_T]) -> AbstractSet[Union[_T_co, _T]]: ...
def __or__(self, s: AbstractSet[_T]) -> AbstractSet[_T_co | _T]: ...
def __sub__(self, s: AbstractSet[Any]) -> AbstractSet[_T_co]: ...
def __xor__(self, s: AbstractSet[_T]) -> AbstractSet[Union[_T_co, _T]]: ...
def __xor__(self, s: AbstractSet[_T]) -> AbstractSet[_T_co | _T]: ...
# TODO: argument can be any container?
def isdisjoint(self, s: AbstractSet[Any]) -> bool: ...
# Implement Sized (but don't have it as a base class).
@@ -236,9 +231,9 @@ class MutableSet(AbstractSet[_T], Generic[_T]):
def clear(self) -> None: ...
def pop(self) -> _T: ...
def remove(self, element: _T) -> None: ...
def __ior__(self, s: AbstractSet[_S]) -> MutableSet[Union[_T, _S]]: ...
def __ior__(self, s: AbstractSet[_S]) -> MutableSet[_T | _S]: ...
def __iand__(self, s: AbstractSet[Any]) -> MutableSet[_T]: ...
def __ixor__(self, s: AbstractSet[_S]) -> MutableSet[Union[_T, _S]]: ...
def __ixor__(self, s: AbstractSet[_S]) -> MutableSet[_T | _S]: ...
def __isub__(self, s: AbstractSet[Any]) -> MutableSet[_T]: ...
class MappingView(object):
@@ -263,11 +258,8 @@ class ValuesView(MappingView, Iterable[_VT_co], Generic[_VT_co]):
class ContextManager(Protocol[_T_co]):
def __enter__(self) -> _T_co: ...
def __exit__(
self,
__exc_type: Optional[Type[BaseException]],
__exc_value: Optional[BaseException],
__traceback: Optional[TracebackType],
) -> Optional[bool]: ...
self, __exc_type: Type[BaseException] | None, __exc_value: BaseException | None, __traceback: TracebackType | None
) -> bool | None: ...
class Mapping(Iterable[_KT], Container[_KT], Generic[_KT, _VT_co]):
# TODO: We wish the key type could also be covariant, but that doesn't work,
@@ -276,9 +268,9 @@ class Mapping(Iterable[_KT], Container[_KT], Generic[_KT, _VT_co]):
def __getitem__(self, k: _KT) -> _VT_co: ...
# Mixin methods
@overload
def get(self, k: _KT) -> Optional[_VT_co]: ...
def get(self, k: _KT) -> _VT_co | None: ...
@overload
def get(self, k: _KT, default: Union[_VT_co, _T]) -> Union[_VT_co, _T]: ...
def get(self, k: _KT, default: _VT_co | _T) -> _VT_co | _T: ...
def keys(self) -> list[_KT]: ...
def values(self) -> list[_VT_co]: ...
def items(self) -> list[Tuple[_KT, _VT_co]]: ...
@@ -299,7 +291,7 @@ class MutableMapping(Mapping[_KT, _VT], Generic[_KT, _VT]):
@overload
def pop(self, k: _KT) -> _VT: ...
@overload
def pop(self, k: _KT, default: Union[_VT, _T] = ...) -> Union[_VT, _T]: ...
def pop(self, k: _KT, default: _VT | _T = ...) -> _VT | _T: ...
def popitem(self) -> Tuple[_KT, _VT]: ...
def setdefault(self, k: _KT, default: _VT = ...) -> _VT: ...
@overload
@@ -346,7 +338,7 @@ class IO(Iterator[AnyStr], Generic[AnyStr]):
@abstractmethod
def tell(self) -> int: ...
@abstractmethod
def truncate(self, size: Optional[int] = ...) -> int: ...
def truncate(self, size: int | None = ...) -> int: ...
@abstractmethod
def writable(self) -> bool: ...
# TODO buffer objects
@@ -362,8 +354,8 @@ class IO(Iterator[AnyStr], Generic[AnyStr]):
def __enter__(self) -> IO[AnyStr]: ...
@abstractmethod
def __exit__(
self, t: Optional[Type[BaseException]], value: Optional[BaseException], traceback: Optional[TracebackType]
) -> Optional[bool]: ...
self, t: Type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None
) -> bool | None: ...
class BinaryIO(IO[str]):
# TODO readinto
@@ -379,7 +371,7 @@ class TextIO(IO[unicode]):
@property
def encoding(self) -> str: ...
@property
def errors(self) -> Optional[str]: ...
def errors(self) -> str | None: ...
@property
def line_buffering(self) -> bool: ...
@property
@@ -392,7 +384,7 @@ class ByteString(Sequence[int], metaclass=ABCMeta): ...
class Match(Generic[AnyStr]):
pos: int
endpos: int
lastindex: Optional[int]
lastindex: int | None
string: AnyStr
# The regular expression object whose match() or search() method produced
@@ -404,8 +396,8 @@ class Match(Generic[AnyStr]):
re: Pattern[Any]
# Can be None if there are no groups or if the last group was unnamed;
# otherwise matches the type of the pattern.
lastgroup: Optional[Any]
def expand(self, template: Union[str, Text]) -> Any: ...
lastgroup: Any | None
def expand(self, template: str | Text) -> Any: ...
@overload
def group(self, group1: int = ...) -> AnyStr: ...
@overload
@@ -416,9 +408,9 @@ class Match(Generic[AnyStr]):
def group(self, group1: str, group2: str, *groups: str) -> Tuple[AnyStr, ...]: ...
def groups(self, default: AnyStr = ...) -> Tuple[AnyStr, ...]: ...
def groupdict(self, default: AnyStr = ...) -> Dict[str, AnyStr]: ...
def start(self, __group: Union[int, str] = ...) -> int: ...
def end(self, __group: Union[int, str] = ...) -> int: ...
def span(self, __group: Union[int, str] = ...) -> Tuple[int, int]: ...
def start(self, __group: int | str = ...) -> int: ...
def end(self, __group: int | str = ...) -> int: ...
def span(self, __group: int | str = ...) -> Tuple[int, int]: ...
@property
def regs(self) -> Tuple[Tuple[int, int], ...]: ... # undocumented
@@ -433,12 +425,12 @@ class Pattern(Generic[AnyStr]):
groupindex: Dict[AnyStr, int]
groups: int
pattern: AnyStr
def search(self, string: _AnyStr2, pos: int = ..., endpos: int = ...) -> Optional[Match[_AnyStr2]]: ...
def match(self, string: _AnyStr2, pos: int = ..., endpos: int = ...) -> Optional[Match[_AnyStr2]]: ...
def search(self, string: _AnyStr2, pos: int = ..., endpos: int = ...) -> Match[_AnyStr2] | None: ...
def match(self, string: _AnyStr2, pos: int = ..., endpos: int = ...) -> Match[_AnyStr2] | None: ...
def split(self, string: _AnyStr2, maxsplit: int = ...) -> List[_AnyStr2]: ...
# Returns either a list of _AnyStr2 or a list of tuples, depending on
# whether there are groups in the pattern.
def findall(self, string: Union[bytes, Text], pos: int = ..., endpos: int = ...) -> List[Any]: ...
def findall(self, string: bytes | Text, pos: int = ..., endpos: int = ...) -> List[Any]: ...
def finditer(self, string: _AnyStr2, pos: int = ..., endpos: int = ...) -> Iterator[Match[_AnyStr2]]: ...
@overload
def sub(self, repl: _AnyStr2, string: _AnyStr2, count: int = ...) -> _AnyStr2: ...
@@ -452,7 +444,7 @@ class Pattern(Generic[AnyStr]):
# Functions
def get_type_hints(
obj: Callable[..., Any], globalns: Optional[Dict[Text, Any]] = ..., localns: Optional[Dict[Text, Any]] = ...
obj: Callable[..., Any], globalns: Dict[Text, Any] | None = ..., localns: Dict[Text, Any] | None = ...
) -> None: ...
@overload
def cast(tp: Type[_T], obj: Any) -> _T: ...