Skip to content
16 changes: 12 additions & 4 deletions mypy/typeshed/stdlib/_typeshed/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,11 @@ Unused: TypeAlias = object # stable
MaybeNone: TypeAlias = Any # stable

# typeshed-internal type aliases to facilitate transition from
# `float` to either `float | int` or `float` (and similar for `complex`).
# When you encounter one of these type aliases, you are encouraged to
# replace them with the correct type. Please don't use them outside typeshed.
# `float` to either `float | int` or `float`. When you encounter this type
# alias, you are encouraged to replace it with the correct type. Please don't
# use it outside typeshed.
# See https://github.com/python/typeshed/issues/16059 for details.
FloatInt: TypeAlias = float | int
ComplexInt: TypeAlias = complex | float | int

# Used to mark arguments that default to a sentinel value. This prevents
# stubtest from complaining about the default value not matching.
Expand Down Expand Up @@ -146,6 +145,15 @@ class SupportsDivMod(Protocol[_T_contra, _T_co]):
class SupportsRDivMod(Protocol[_T_contra, _T_co]):
def __rdivmod__(self, other: _T_contra, /) -> _T_co: ...

class SupportsRAnd(Protocol[_T_contra, _T_co]):
def __rand__(self, other: _T_contra, /) -> _T_co: ...

class SupportsROr(Protocol[_T_contra, _T_co]):
def __ror__(self, other: _T_contra, /) -> _T_co: ...

class SupportsRXor(Protocol[_T_contra, _T_co]):
def __rxor__(self, other: _T_contra, /) -> _T_co: ...

# This protocol is generic over the iterator type, while Iterable is
# generic over the type that is iterated over.
class SupportsIter(Protocol[_T_co]):
Expand Down
4 changes: 2 additions & 2 deletions mypy/typeshed/stdlib/_weakrefset.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ class WeakSet(MutableSet[_T]):
def difference(self, other: Iterable[_T]) -> Self: ...
def __sub__(self, other: Iterable[Any]) -> Self: ...
def difference_update(self, other: Iterable[Any]) -> None: ...
def __isub__(self, other: Iterable[Any]) -> Self: ...
def __isub__(self, other: Iterable[Any]) -> Self: ... # type: ignore[override]
def intersection(self, other: Iterable[_T]) -> Self: ...
def __and__(self, other: Iterable[Any]) -> Self: ...
def intersection_update(self, other: Iterable[Any]) -> None: ...
def __iand__(self, other: Iterable[Any]) -> Self: ...
def __iand__(self, other: Iterable[Any]) -> Self: ... # type: ignore[override]
def issubset(self, other: Iterable[_T]) -> bool: ...
def __le__(self, other: Iterable[_T]) -> bool: ...
def __lt__(self, other: Iterable[_T]) -> bool: ...
Expand Down
2 changes: 1 addition & 1 deletion mypy/typeshed/stdlib/ast.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1711,7 +1711,7 @@ else:
if sys.version_info < (3, 14):
@deprecated("Removed in Python 3.14. Use `ast.Constant` instead.")
class Num(Constant, metaclass=_ABC):
def __new__(cls, n: complex, **kwargs: Unpack[_Attributes]) -> Constant: ... # type: ignore[misc] # pyright: ignore[reportInconsistentConstructor]
def __new__(cls, n: complex | float | int, **kwargs: Unpack[_Attributes]) -> Constant: ... # type: ignore[misc] # pyright: ignore[reportInconsistentConstructor]

@deprecated("Removed in Python 3.14. Use `ast.Constant` instead.")
class Str(Constant, metaclass=_ABC):
Expand Down
86 changes: 56 additions & 30 deletions mypy/typeshed/stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ from _typeshed import (
SupportsLenAndGetItem,
SupportsNext,
SupportsRAdd,
SupportsRAnd,
SupportsRDivMod,
SupportsRichComparison,
SupportsRichComparisonT,
SupportsROr,
SupportsRSub,
SupportsRXor,
SupportsWrite,
)
from collections.abc import Awaitable, Callable, Hashable, Iterable, Iterator, MutableSet, Set as AbstractSet, Sized
Expand Down Expand Up @@ -80,6 +84,7 @@ _KT = TypeVar("_KT")
_VT = TypeVar("_VT")
_VT_co = TypeVar("_VT_co", covariant=True)
_S = TypeVar("_S")
_R = TypeVar("_R")
_T1 = TypeVar("_T1")
_T2 = TypeVar("_T2")
_T3 = TypeVar("_T3")
Expand Down Expand Up @@ -428,7 +433,7 @@ class float:
def __format__(self, format_spec: str, /) -> str: ...
if sys.version_info >= (3, 14):
@classmethod
def from_number(cls, number: float | SupportsIndex | SupportsFloat, /) -> Self: ...
def from_number(cls, number: SupportsIndex | SupportsFloat, /) -> Self: ...

@disjoint_base
class complex:
Expand All @@ -440,23 +445,23 @@ class complex:
imag: complex | SupportsFloat | SupportsIndex = 0,
) -> Self: ...
@overload
def __new__(cls, real: str | SupportsComplex | SupportsFloat | SupportsIndex | complex) -> Self: ...
def __new__(cls, real: str | SupportsComplex | SupportsFloat | SupportsIndex | complex | float | int) -> Self: ...

@property
def real(self) -> float: ...
@property
def imag(self) -> float: ...
def conjugate(self) -> complex: ...
def __add__(self, value: complex, /) -> complex: ...
def __sub__(self, value: complex, /) -> complex: ...
def __mul__(self, value: complex, /) -> complex: ...
def __pow__(self, value: complex, mod: None = None, /) -> complex: ...
def __truediv__(self, value: complex, /) -> complex: ...
def __radd__(self, value: complex, /) -> complex: ...
def __rsub__(self, value: complex, /) -> complex: ...
def __rmul__(self, value: complex, /) -> complex: ...
def __rpow__(self, value: complex, mod: None = None, /) -> complex: ...
def __rtruediv__(self, value: complex, /) -> complex: ...
def __add__(self, value: complex | float | int, /) -> complex: ...
def __sub__(self, value: complex | float | int, /) -> complex: ...
def __mul__(self, value: complex | float | int, /) -> complex: ...
def __pow__(self, value: complex | float | int, mod: None = None, /) -> complex: ...
def __truediv__(self, value: complex | float | int, /) -> complex: ...
def __radd__(self, value: complex | float | int, /) -> complex: ...
def __rsub__(self, value: complex | float | int, /) -> complex: ...
def __rmul__(self, value: complex | float | int, /) -> complex: ...
def __rpow__(self, value: complex | float | int, mod: None = None, /) -> complex: ...
def __rtruediv__(self, value: complex | float | int, /) -> complex: ...
def __eq__(self, value: object, /) -> bool: ...
def __ne__(self, value: object, /) -> bool: ...
def __neg__(self) -> complex: ...
Expand All @@ -469,7 +474,7 @@ class complex:
def __complex__(self) -> complex: ...
if sys.version_info >= (3, 14):
@classmethod
def from_number(cls, number: complex | SupportsComplex | SupportsFloat | SupportsIndex, /) -> Self: ...
def from_number(cls, number: SupportsComplex | SupportsFloat | SupportsIndex, /) -> Self: ...

@type_check_only
class _FormatMapMapping(Protocol):
Expand Down Expand Up @@ -1294,6 +1299,8 @@ if sys.version_info >= (3, 15):
def __getitem__(self, key: _KT, /) -> _VT_co: ...
def __reversed__(self) -> Iterator[_KT]: ...
def __iter__(self) -> Iterator[_KT]: ...
def __eq__(self, value: object, /) -> bool: ...
def __ne__(self, value: object, /) -> bool: ...
def __hash__(self) -> int: ...
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
def __or__(self, value: dict[_T1, _T2] | frozendict[_T1, _T2], /) -> frozendict[_KT | _T1, _VT_co | _T2]: ...
Expand Down Expand Up @@ -1328,32 +1335,48 @@ class set(MutableSet[_T]):
def __len__(self) -> int: ...
def __contains__(self, o: object, /) -> bool: ...
def __iter__(self) -> Iterator[_T]: ...
def __and__(self, value: AbstractSet[object], /) -> set[_T]: ...
def __iand__(self, value: AbstractSet[object], /) -> Self: ...
def __and__(self, value: set[Any] | frozenset[Any], /) -> set[_T]: ... # type: ignore[override]

@overload # type: ignore[misc]
def __iand__(self, value: set[Any] | frozenset[Any], /) -> Self: ...
@overload
def __iand__(self, value: SupportsRAnd[set[_T], _R], /) -> _R: ...

@overload # type: ignore[override]
def __rand__(self, value: set[_S], /) -> set[_S]: ...
@overload
def __rand__(self, value: frozenset[_S], /) -> frozenset[_S]: ...

def __or__(self, value: AbstractSet[_S], /) -> set[_T | _S]: ...
def __ior__(self, value: AbstractSet[_T], /) -> Self: ... # type: ignore[override,misc]
def __or__(self, value: set[_S] | frozenset[_S], /) -> set[_T | _S]: ... # type: ignore[override]

@overload # type: ignore[override,misc]
def __ior__(self, value: set[_T] | frozenset[_T], /) -> Self: ...
@overload
def __ior__(self, value: SupportsROr[set[_T], _R], /) -> _R: ...

@overload # type: ignore[override]
def __ror__(self, value: set[_S], /) -> set[_T | _S]: ...
@overload
def __ror__(self, value: frozenset[_S], /) -> frozenset[_T | _S]: ...

def __sub__(self, value: AbstractSet[object], /) -> set[_T]: ...
def __isub__(self, value: AbstractSet[object], /) -> Self: ...
def __sub__(self, value: set[Any] | frozenset[Any], /) -> set[_T]: ... # type: ignore[override]

@overload # type: ignore[misc]
def __isub__(self, value: set[Any] | frozenset[Any], /) -> Self: ...
@overload
def __isub__(self, value: SupportsRSub[set[_T], _R], /) -> _R: ...

@overload # type: ignore[override]
def __rsub__(self, value: set[_S], /) -> set[_S]: ...
@overload
def __rsub__(self, value: frozenset[_S], /) -> frozenset[_S]: ...

def __xor__(self, value: set[_S] | frozenset[_S], /) -> set[_T | _S]: ... # type: ignore[override]
def __ixor__(self, value: AbstractSet[_T], /) -> Self: ... # type: ignore[override,misc]

@overload # type: ignore[override,misc]
def __ixor__(self, value: set[_T] | frozenset[_T], /) -> Self: ...
@overload
def __ixor__(self, value: SupportsRXor[set[_T], _R], /) -> _R: ...

@overload # type: ignore[override]
def __rxor__(self, value: set[_S], /) -> set[_T | _S]: ...
Expand Down Expand Up @@ -1386,23 +1409,25 @@ class frozenset(AbstractSet[_T_co]):
def __len__(self) -> int: ...
def __contains__(self, o: object, /) -> bool: ...
def __iter__(self) -> Iterator[_T_co]: ...
def __and__(self, value: AbstractSet[object], /) -> frozenset[_T_co]: ...
# The binary operators only support set and frozenset. For other operands,
# Python falls back to the operand's reflected method.
def __and__(self, value: set[Any] | frozenset[Any], /) -> frozenset[_T_co]: ... # type: ignore[override]

@overload
@overload # type: ignore[override]
def __rand__(self, value: set[_S], /) -> set[_S]: ...
@overload
def __rand__(self, value: frozenset[_S], /) -> frozenset[_S]: ...

def __or__(self, value: AbstractSet[_S], /) -> frozenset[_T_co | _S]: ...
def __or__(self, value: set[_S] | frozenset[_S], /) -> frozenset[_T_co | _S]: ... # type: ignore[override]

@overload
@overload # type: ignore[override]
def __ror__(self, value: set[_S], /) -> set[_T_co | _S]: ...
@overload
def __ror__(self, value: frozenset[_S], /) -> frozenset[_T_co | _S]: ...

def __sub__(self, value: AbstractSet[object], /) -> frozenset[_T_co]: ...
def __sub__(self, value: set[Any] | frozenset[Any], /) -> frozenset[_T_co]: ... # type: ignore[override]

@overload
@overload # type: ignore[override]
def __rsub__(self, value: set[_S], /) -> set[_S]: ...
@overload
def __rsub__(self, value: frozenset[_S], /) -> frozenset[_S]: ...
Expand Down Expand Up @@ -1474,6 +1499,7 @@ class property:
fdel: Callable[[Any], None] | None = None,
doc: str | None = None,
) -> None: ...
def __set_name__(self, owner: type, name: str, /) -> None: ...
def getter(self, fget: Callable[[Any], Any], /) -> property: ...
def setter(self, fset: Callable[[Any, Any], None], /) -> property: ...
def deleter(self, fdel: Callable[[Any], None], /) -> property: ...
Expand Down Expand Up @@ -2059,17 +2085,17 @@ def pow(base: float, exp: int, mod: None = None) -> float: ...
# return type must be Any (same as complex base, complex exp),
# as `float | complex` causes too many false-positive errors
@overload
def pow(base: float, exp: complex | _SupportsSomeKindOfPow, mod: None = None) -> Any: ...
def pow(base: float, exp: complex | float | int | _SupportsSomeKindOfPow, mod: None = None) -> Any: ...
@overload
def pow(base: complex, exp: complex | _SupportsSomeKindOfPow, mod: None = None) -> complex: ...
def pow(base: complex, exp: complex | float | int | _SupportsSomeKindOfPow, mod: None = None) -> complex: ...
@overload
def pow(base: _SupportsPow2[_E_contra, _T_co], exp: _E_contra, mod: None = None) -> _T_co: ... # type: ignore[overload-overlap]
@overload
def pow(base: _SupportsPow3NoneOnly[_E_contra, _T_co], exp: _E_contra, mod: None = None) -> _T_co: ... # type: ignore[overload-overlap]
@overload
def pow(base: _SupportsPow3[_E_contra, _M_contra, _T_co], exp: _E_contra, mod: _M_contra) -> _T_co: ...
@overload
def pow(base: _SupportsSomeKindOfPow, exp: float, mod: None = None) -> Any: ...
def pow(base: _SupportsSomeKindOfPow, exp: float | int, mod: None = None) -> Any: ...
@overload
def pow(base: _SupportsSomeKindOfPow, exp: complex, mod: None = None) -> complex: ...

Expand Down Expand Up @@ -2221,7 +2247,7 @@ if sys.version_info >= (3, 15):
locals: Mapping[str, object] | None = None,
fromlist: Sequence[str] | None = (),
level: int = 0,
) -> Any: ...
) -> types.LazyImportType: ...

def __build_class__(func: Callable[[], CellType | Any], name: str, /, *bases: Any, metaclass: Any = ..., **kwds: Any) -> Any: ...

Expand Down
2 changes: 1 addition & 1 deletion mypy/typeshed/stdlib/cmath.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ nanj: Final[complex]
tau: Final[float]

_F: TypeAlias = SupportsFloat | SupportsIndex
_C: TypeAlias = SupportsFloat | SupportsComplex | SupportsIndex | complex
_C: TypeAlias = SupportsComplex | SupportsFloat | SupportsIndex | complex | float | int

def acos(z: _C, /) -> complex: ...
def acosh(z: _C, /) -> complex: ...
Expand Down
2 changes: 1 addition & 1 deletion mypy/typeshed/stdlib/functools.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ class _SingleDispatchCallable(Generic[_T]):
registry: types.MappingProxyType[Any, Callable[..., _T]]
def dispatch(self, cls: Any) -> Callable[..., _T]: ...

# @fun.register(complex)
# @fun.register(complex | float | int)
# def _(arg, verbose=False): ...
@overload
def register(self, cls: _RegType, func: None = None) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ...
Expand Down
6 changes: 5 additions & 1 deletion mypy/typeshed/stdlib/multiprocessing/context.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,11 @@ class DefaultContext(BaseContext):
else:
def __init__(self, context: BaseContext) -> None: ...

def get_start_method(self, allow_none: bool = False) -> str: ...
@overload
def get_start_method(self, allow_none: Literal[False] = False) -> str: ...
@overload
def get_start_method(self, allow_none: bool) -> str | None: ...

def get_all_start_methods(self) -> list[str]: ...

_default_context: DefaultContext
Expand Down
8 changes: 4 additions & 4 deletions mypy/typeshed/stdlib/multiprocessing/managers.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -180,21 +180,21 @@ if sys.version_info >= (3, 14):
def __contains__(self, o: object, /) -> bool: ...
def __iter__(self) -> Iterator[_T]: ...
def __and__(self, value: AbstractSet[object], /) -> set[_T]: ...
def __iand__(self, value: AbstractSet[object], /) -> Self: ...
def __iand__(self, value: AbstractSet[object], /) -> Self: ... # type: ignore[override]
def __or__(self, value: AbstractSet[_S], /) -> set[_T | _S]: ...
def __ior__(self, value: AbstractSet[_T], /) -> Self: ... # type: ignore[override,misc]
def __sub__(self, value: AbstractSet[_T | None], /) -> set[_T]: ...
def __isub__(self, value: AbstractSet[object], /) -> Self: ...
def __isub__(self, value: AbstractSet[object], /) -> Self: ... # type: ignore[override]
def __xor__(self, value: AbstractSet[_S], /) -> set[_T | _S]: ...
def __ixor__(self, value: AbstractSet[_T], /) -> Self: ... # type: ignore[override,misc]
def __le__(self, value: AbstractSet[object], /) -> bool: ...
def __lt__(self, value: AbstractSet[object], /) -> bool: ...
def __ge__(self, value: AbstractSet[object], /) -> bool: ...
def __gt__(self, value: AbstractSet[object], /) -> bool: ...
def __eq__(self, value: object, /) -> bool: ...
def __rand__(self, value: AbstractSet[object], /) -> set[_T]: ...
def __rand__(self, value: AbstractSet[object], /) -> set[_T]: ... # type: ignore[override]
def __ror__(self, value: AbstractSet[_S], /) -> set[_T | _S]: ... # type: ignore[misc]
def __rsub__(self, value: AbstractSet[_T], /) -> set[_T]: ...
def __rsub__(self, value: AbstractSet[_T], /) -> set[_T]: ... # type: ignore[override]
def __rxor__(self, value: AbstractSet[_S], /) -> set[_T | _S]: ... # type: ignore[override,misc]
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...

Expand Down
2 changes: 1 addition & 1 deletion mypy/typeshed/stdlib/optparse.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ SUPPRESS_HELP: Final = "SUPPRESSHELP"
SUPPRESS_USAGE: Final = "SUPPRESSUSAGE"

# Can return complex, float, or int depending on the option's type
def check_builtin(option: Option, opt: str, value: str) -> complex: ...
def check_builtin(option: Option, opt: str, value: str) -> complex | float | int: ...
def check_choice(option: Option, opt: str, value: str) -> str: ...

class OptParseError(Exception):
Expand Down
18 changes: 9 additions & 9 deletions mypy/typeshed/stdlib/pydoc.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ class HTMLRepr(Repr):
def __init__(self) -> None: ...
def escape(self, text: str) -> str: ...
def repr(self, object: object) -> str: ...
def repr1(self, x: object, level: complex) -> str: ...
def repr_string(self, x: str, level: complex) -> str: ...
def repr_str(self, x: str, level: complex) -> str: ...
def repr_instance(self, x: object, level: complex) -> str: ...
def repr_unicode(self, x: AnyStr, level: complex) -> str: ...
def repr1(self, x: object, level: int) -> str: ...
def repr_string(self, x: str, level: int) -> str: ...
def repr_str(self, x: str, level: int) -> str: ...
def repr_instance(self, x: object, level: int) -> str: ...
def repr_unicode(self, x: AnyStr, level: int) -> str: ...

class HTMLDoc(Doc):
_repr_instance: HTMLRepr
Expand Down Expand Up @@ -190,10 +190,10 @@ class HTMLDoc(Doc):

class TextRepr(Repr):
def __init__(self) -> None: ...
def repr1(self, x: object, level: complex) -> str: ...
def repr_string(self, x: str, level: complex) -> str: ...
def repr_str(self, x: str, level: complex) -> str: ...
def repr_instance(self, x: object, level: complex) -> str: ...
def repr1(self, x: object, level: int) -> str: ...
def repr_string(self, x: str, level: int) -> str: ...
def repr_str(self, x: str, level: int) -> str: ...
def repr_instance(self, x: object, level: int) -> str: ...

class TextDoc(Doc):
_repr_instance: TextRepr
Expand Down
2 changes: 2 additions & 0 deletions mypy/typeshed/stdlib/re.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,8 @@ def subn(
def escape(pattern: AnyStr) -> AnyStr: ...
@overload
def escape(pattern: ReadableBuffer) -> bytes: ...
@overload
def escape(pattern: str | ReadableBuffer) -> str | bytes: ...

def purge() -> None: ...

Expand Down
Loading
Loading