From 1e7372aa5711398e3d18a9e37a2c1e9c2d55fc76 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Mon, 9 Nov 2026 18:38:32 +0100 Subject: [PATCH 1/6] Replace `complex` - Replace most instances of `_typeshed.ComplexInt` (as a marker that the exact type needs to be checked). - Replace a few instances with `complex | float | int` where all types are accepted. - Left a few instances that were either already an union with `float` and/or `int` or only accept `complex`. Part of #16059 --- stdlib/ast.pyi | 4 +-- stdlib/builtins.pyi | 47 +++++++++++++------------- stdlib/cmath.pyi | 43 +++++++++++------------ stdlib/collections/__init__.pyi | 4 +-- stdlib/ctypes/__init__.pyi | 8 ++--- stdlib/decimal.pyi | 3 +- stdlib/fractions.pyi | 25 +++++++------- stdlib/functools.pyi | 2 +- stdlib/numbers.pyi | 5 +-- stdlib/optparse.pyi | 2 +- stdlib/pydoc.pyi | 20 +++++------ stdlib/typing.pyi | 12 +++++-- stdlib/typing_extensions.pyi | 4 +-- stubs/PyYAML/yaml/constructor.pyi | 4 +-- stubs/PyYAML/yaml/representer.pyi | 4 +-- stubs/cffi/_cffi_backend.pyi | 4 +-- stubs/pyasn1/pyasn1/type/univ.pyi | 6 ++-- stubs/seaborn/seaborn/_core/typing.pyi | 4 +-- stubs/seaborn/seaborn/utils.pyi | 4 +-- 19 files changed, 109 insertions(+), 96 deletions(-) diff --git a/stdlib/ast.pyi b/stdlib/ast.pyi index f84c93e7953e..72d879892264 100644 --- a/stdlib/ast.pyi +++ b/stdlib/ast.pyi @@ -8,7 +8,7 @@ from _ast import ( PyCF_ONLY_AST as PyCF_ONLY_AST, PyCF_TYPE_COMMENTS as PyCF_TYPE_COMMENTS, ) -from _typeshed import ReadableBuffer, Unused +from _typeshed import ComplexInt, ReadableBuffer, Unused from collections.abc import Iterable, Iterator, Sequence from types import EllipsisType from typing import Any, ClassVar, Generic, Literal, TypedDict, TypeVar as _TypeVar, overload, type_check_only @@ -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: ComplexInt, **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): diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 1628f1bbf760..86bf908ccfdf 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -6,6 +6,7 @@ import types from _collections_abc import dict_items, dict_keys, dict_values from _typeshed import ( AnnotationForm, + ComplexInt, ConvertibleToFloat, ConvertibleToInt, FileDescriptorOrPath, @@ -397,7 +398,7 @@ class float: @overload def __rpow__(self, value: _PositiveInteger, mod: None = None, /) -> float: ... @overload - def __rpow__(self, value: _NegativeInteger, mod: None = None, /) -> complex: ... + def __rpow__(self, value: _NegativeInteger, mod: None = None, /) -> ComplexInt: ... # Returning `complex` for the general case gives too many false-positive errors. @overload def __rpow__(self, value: float, mod: None = None, /) -> Any: ... @@ -436,40 +437,40 @@ class complex: @overload def __new__( cls, - real: complex | SupportsComplex | SupportsFloat | SupportsIndex = 0, - imag: complex | SupportsFloat | SupportsIndex = 0, + real: complex | float | int | SupportsComplex | SupportsFloat | SupportsIndex = 0, + imag: complex | float | int | 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 conjugate(self) -> ComplexInt: ... + def __add__(self, value: ComplexInt, /) -> ComplexInt: ... + def __sub__(self, value: ComplexInt, /) -> ComplexInt: ... + def __mul__(self, value: ComplexInt, /) -> ComplexInt: ... + def __pow__(self, value: ComplexInt, mod: None = None, /) -> ComplexInt: ... + def __truediv__(self, value: ComplexInt, /) -> ComplexInt: ... + def __radd__(self, value: ComplexInt, /) -> ComplexInt: ... + def __rsub__(self, value: ComplexInt, /) -> ComplexInt: ... + def __rmul__(self, value: ComplexInt, /) -> ComplexInt: ... + def __rpow__(self, value: ComplexInt, mod: None = None, /) -> ComplexInt: ... + def __rtruediv__(self, value: ComplexInt, /) -> ComplexInt: ... def __eq__(self, value: object, /) -> bool: ... def __ne__(self, value: object, /) -> bool: ... - def __neg__(self) -> complex: ... - def __pos__(self) -> complex: ... + def __neg__(self) -> ComplexInt: ... + def __pos__(self) -> ComplexInt: ... def __abs__(self) -> float: ... def __hash__(self) -> int: ... def __bool__(self) -> bool: ... def __format__(self, format_spec: str, /) -> str: ... if sys.version_info >= (3, 11): - def __complex__(self) -> complex: ... + def __complex__(self) -> ComplexInt: ... if sys.version_info >= (3, 14): @classmethod - def from_number(cls, number: complex | SupportsComplex | SupportsFloat | SupportsIndex, /) -> Self: ... + def from_number(cls, number: complex | float | int | SupportsComplex | SupportsFloat | SupportsIndex, /) -> Self: ... @type_check_only class _FormatMapMapping(Protocol): @@ -2177,7 +2178,7 @@ def pow(base: int, exp: int, mod: None = None) -> Any: ... @overload def pow(base: _PositiveInteger, exp: float, mod: None = None) -> float: ... @overload -def pow(base: _NegativeInteger, exp: float, mod: None = None) -> complex: ... +def pow(base: _NegativeInteger, exp: float, mod: None = None) -> ComplexInt: ... @overload def pow(base: float, exp: int, mod: None = None) -> float: ... @@ -2185,9 +2186,9 @@ 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: ComplexInt | _SupportsSomeKindOfPow, mod: None = None) -> Any: ... @overload -def pow(base: complex, exp: complex | _SupportsSomeKindOfPow, mod: None = None) -> complex: ... +def pow(base: ComplexInt, exp: ComplexInt | _SupportsSomeKindOfPow, mod: None = None) -> ComplexInt: ... @overload def pow(base: _SupportsPow2[_E_contra, _T_co], exp: _E_contra, mod: None = None) -> _T_co: ... # type: ignore[overload-overlap] @overload @@ -2197,7 +2198,7 @@ def pow(base: _SupportsPow3[_E_contra, _M_contra, _T_co], exp: _E_contra, mod: _ @overload def pow(base: _SupportsSomeKindOfPow, exp: float, mod: None = None) -> Any: ... @overload -def pow(base: _SupportsSomeKindOfPow, exp: complex, mod: None = None) -> complex: ... +def pow(base: _SupportsSomeKindOfPow, exp: ComplexInt, mod: None = None) -> ComplexInt: ... quit: _sitebuiltins.Quitter diff --git a/stdlib/cmath.pyi b/stdlib/cmath.pyi index 554eb54e2e4c..6bda00988b46 100644 --- a/stdlib/cmath.pyi +++ b/stdlib/cmath.pyi @@ -1,36 +1,37 @@ +from _typeshed import ComplexInt from typing import Final, SupportsComplex, SupportsFloat, SupportsIndex, TypeAlias e: Final[float] pi: Final[float] inf: Final[float] -infj: Final[complex] +infj: Final[ComplexInt] nan: Final[float] -nanj: Final[complex] +nanj: Final[ComplexInt] tau: Final[float] -_F: TypeAlias = SupportsFloat | SupportsIndex -_C: TypeAlias = SupportsFloat | SupportsComplex | SupportsIndex | complex +_F: TypeAlias = SupportsIndex | SupportsFloat +_C: TypeAlias = SupportsIndex | SupportsFloat | SupportsComplex | int | float | complex -def acos(z: _C, /) -> complex: ... -def acosh(z: _C, /) -> complex: ... -def asin(z: _C, /) -> complex: ... -def asinh(z: _C, /) -> complex: ... -def atan(z: _C, /) -> complex: ... -def atanh(z: _C, /) -> complex: ... -def cos(z: _C, /) -> complex: ... -def cosh(z: _C, /) -> complex: ... -def exp(z: _C, /) -> complex: ... +def acos(z: _C, /) -> ComplexInt: ... +def acosh(z: _C, /) -> ComplexInt: ... +def asin(z: _C, /) -> ComplexInt: ... +def asinh(z: _C, /) -> ComplexInt: ... +def atan(z: _C, /) -> ComplexInt: ... +def atanh(z: _C, /) -> ComplexInt: ... +def cos(z: _C, /) -> ComplexInt: ... +def cosh(z: _C, /) -> ComplexInt: ... +def exp(z: _C, /) -> ComplexInt: ... def isclose(a: _C, b: _C, *, rel_tol: SupportsFloat = 1e-09, abs_tol: SupportsFloat = 0.0) -> bool: ... def isinf(z: _C, /) -> bool: ... def isnan(z: _C, /) -> bool: ... -def log(z: _C, base: _C = ..., /) -> complex: ... -def log10(z: _C, /) -> complex: ... +def log(z: _C, base: _C = ..., /) -> ComplexInt: ... +def log10(z: _C, /) -> ComplexInt: ... def phase(z: _C, /) -> float: ... def polar(z: _C, /) -> tuple[float, float]: ... -def rect(r: _F, phi: _F, /) -> complex: ... -def sin(z: _C, /) -> complex: ... -def sinh(z: _C, /) -> complex: ... -def sqrt(z: _C, /) -> complex: ... -def tan(z: _C, /) -> complex: ... -def tanh(z: _C, /) -> complex: ... +def rect(r: _F, phi: _F, /) -> ComplexInt: ... +def sin(z: _C, /) -> ComplexInt: ... +def sinh(z: _C, /) -> ComplexInt: ... +def sqrt(z: _C, /) -> ComplexInt: ... +def tan(z: _C, /) -> ComplexInt: ... +def tanh(z: _C, /) -> ComplexInt: ... def isfinite(z: _C, /) -> bool: ... diff --git a/stdlib/collections/__init__.pyi b/stdlib/collections/__init__.pyi index bce72464fd75..becd37036825 100644 --- a/stdlib/collections/__init__.pyi +++ b/stdlib/collections/__init__.pyi @@ -1,6 +1,6 @@ import sys from _collections_abc import dict_items, dict_keys, dict_values -from _typeshed import SupportsItems, SupportsKeysAndGetItem, SupportsRichComparison, SupportsRichComparisonT +from _typeshed import ComplexInt, SupportsItems, SupportsKeysAndGetItem, SupportsRichComparison, SupportsRichComparisonT from collections.abc import ( Callable, ItemsView, @@ -176,7 +176,7 @@ class UserString(Sequence[UserString]): def __init__(self, seq: object) -> None: ... def __int__(self) -> int: ... def __float__(self) -> float: ... - def __complex__(self) -> complex: ... + def __complex__(self) -> ComplexInt: ... def __getnewargs__(self) -> tuple[str]: ... def __lt__(self, string: str | UserString) -> bool: ... def __le__(self, string: str | UserString) -> bool: ... diff --git a/stdlib/ctypes/__init__.pyi b/stdlib/ctypes/__init__.pyi index 7d133506af93..9f9b418ec295 100644 --- a/stdlib/ctypes/__init__.pyi +++ b/stdlib/ctypes/__init__.pyi @@ -23,7 +23,7 @@ from _ctypes import ( set_errno as set_errno, sizeof as sizeof, ) -from _typeshed import StrPath, SupportsBool, SupportsLen +from _typeshed import ComplexInt, StrPath, SupportsBool, SupportsLen from ctypes._endian import BigEndianStructure as BigEndianStructure, LittleEndianStructure as LittleEndianStructure from types import GenericAlias from typing import Any, ClassVar, Final, Generic, Literal, TypeAlias, TypeVar, overload, type_check_only @@ -333,7 +333,7 @@ if sys.version_info >= (3, 14) and sys.platform != "win32": # NOTE: currently (3.14.4) the `__ctype_{be,le}__` attributes of these complex types are missing at runtime: # https://github.com/python/cpython/issues/148464 - class c_double_complex(_SimpleCData[complex]): + class c_double_complex(_SimpleCData[ComplexInt]): if sys.version_info >= (3, 15): _type_: ClassVar[Literal["Zd"]] else: @@ -341,7 +341,7 @@ if sys.version_info >= (3, 14) and sys.platform != "win32": __ctype_be__: ClassVar[type[Self]] __ctype_le__: ClassVar[type[Self]] - class c_float_complex(_SimpleCData[complex]): + class c_float_complex(_SimpleCData[ComplexInt]): if sys.version_info >= (3, 15): _type_: ClassVar[Literal["Zf"]] else: @@ -349,7 +349,7 @@ if sys.version_info >= (3, 14) and sys.platform != "win32": __ctype_be__: ClassVar[type[Self]] __ctype_le__: ClassVar[type[Self]] - class c_longdouble_complex(_SimpleCData[complex]): + class c_longdouble_complex(_SimpleCData[ComplexInt]): if sys.version_info >= (3, 15): _type_: ClassVar[Literal["Zg"]] else: diff --git a/stdlib/decimal.pyi b/stdlib/decimal.pyi index f116603cf0f2..412a60c01129 100644 --- a/stdlib/decimal.pyi +++ b/stdlib/decimal.pyi @@ -24,6 +24,7 @@ from _decimal import ( localcontext as localcontext, setcontext as setcontext, ) +from _typeshed import ComplexInt from collections.abc import Container, Sequence from types import TracebackType from typing import Any, ClassVar, Literal, NamedTuple, TypeAlias, final, overload, type_check_only @@ -117,7 +118,7 @@ class Decimal: @property def imag(self) -> Decimal: ... def conjugate(self) -> Decimal: ... - def __complex__(self) -> complex: ... + def __complex__(self) -> ComplexInt: ... @overload def __round__(self) -> int: ... diff --git a/stdlib/fractions.pyi b/stdlib/fractions.pyi index 42947f2e2266..ddb887cb89bf 100644 --- a/stdlib/fractions.pyi +++ b/stdlib/fractions.pyi @@ -1,4 +1,5 @@ import sys +from _typeshed import ComplexInt from collections.abc import Callable from decimal import Decimal from numbers import Rational, Real @@ -43,56 +44,56 @@ class Fraction(Rational): @overload def __add__(a, b: float) -> float: ... @overload - def __add__(a, b: complex) -> complex: ... + def __add__(a, b: ComplexInt) -> ComplexInt: ... @overload def __radd__(b, a: int | Fraction) -> Fraction: ... @overload def __radd__(b, a: float) -> float: ... @overload - def __radd__(b, a: complex) -> complex: ... + def __radd__(b, a: ComplexInt) -> ComplexInt: ... @overload def __sub__(a, b: int | Fraction) -> Fraction: ... @overload def __sub__(a, b: float) -> float: ... @overload - def __sub__(a, b: complex) -> complex: ... + def __sub__(a, b: ComplexInt) -> ComplexInt: ... @overload def __rsub__(b, a: int | Fraction) -> Fraction: ... @overload def __rsub__(b, a: float) -> float: ... @overload - def __rsub__(b, a: complex) -> complex: ... + def __rsub__(b, a: ComplexInt) -> ComplexInt: ... @overload def __mul__(a, b: int | Fraction) -> Fraction: ... @overload def __mul__(a, b: float) -> float: ... @overload - def __mul__(a, b: complex) -> complex: ... + def __mul__(a, b: ComplexInt) -> ComplexInt: ... @overload def __rmul__(b, a: int | Fraction) -> Fraction: ... @overload def __rmul__(b, a: float) -> float: ... @overload - def __rmul__(b, a: complex) -> complex: ... + def __rmul__(b, a: ComplexInt) -> ComplexInt: ... @overload def __truediv__(a, b: int | Fraction) -> Fraction: ... @overload def __truediv__(a, b: float) -> float: ... @overload - def __truediv__(a, b: complex) -> complex: ... + def __truediv__(a, b: ComplexInt) -> ComplexInt: ... @overload def __rtruediv__(b, a: int | Fraction) -> Fraction: ... @overload def __rtruediv__(b, a: float) -> float: ... @overload - def __rtruediv__(b, a: complex) -> complex: ... + def __rtruediv__(b, a: ComplexInt) -> ComplexInt: ... @overload def __floordiv__(a, b: int | Fraction) -> int: ... @@ -130,25 +131,25 @@ class Fraction(Rational): @overload def __pow__(a, b: float | Fraction, modulo: None = None) -> float: ... @overload - def __pow__(a, b: complex, modulo: None = None) -> complex: ... + def __pow__(a, b: ComplexInt, modulo: None = None) -> ComplexInt: ... else: @overload def __pow__(a, b: int) -> Fraction: ... @overload def __pow__(a, b: float | Fraction) -> float: ... @overload - def __pow__(a, b: complex) -> complex: ... + def __pow__(a, b: ComplexInt) -> ComplexInt: ... if sys.version_info >= (3, 14): @overload def __rpow__(b, a: float | Fraction, modulo: None = None) -> float: ... @overload - def __rpow__(b, a: complex, modulo: None = None) -> complex: ... + def __rpow__(b, a: ComplexInt, modulo: None = None) -> ComplexInt: ... else: @overload def __rpow__(b, a: float | Fraction) -> float: ... @overload - def __rpow__(b, a: complex) -> complex: ... + def __rpow__(b, a: ComplexInt) -> ComplexInt: ... def __pos__(a) -> Fraction: ... def __neg__(a) -> Fraction: ... diff --git a/stdlib/functools.pyi b/stdlib/functools.pyi index 42041befd999..da44cbd042bd 100644 --- a/stdlib/functools.pyi +++ b/stdlib/functools.pyi @@ -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(ComplexInt) # def _(arg, verbose=False): ... @overload def register(self, cls: _RegType, func: None = None) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ... diff --git a/stdlib/numbers.pyi b/stdlib/numbers.pyi index 434e52c4cac8..c31791297ee6 100644 --- a/stdlib/numbers.pyi +++ b/stdlib/numbers.pyi @@ -7,6 +7,7 @@ # (since type checkers don't see `complex` as a subtype of `numbers.Complex`, # nor `float` as a subtype of `numbers.Real`, etc.) +from _typeshed import ComplexInt from abc import ABCMeta, abstractmethod from typing import ClassVar, Literal, Protocol, overload, type_check_only @@ -70,7 +71,7 @@ class Number(metaclass=ABCMeta): class Complex(Number, _ComplexLike): __slots__ = () @abstractmethod - def __complex__(self) -> complex: ... + def __complex__(self) -> ComplexInt: ... def __bool__(self) -> bool: ... @property @abstractmethod @@ -142,7 +143,7 @@ class Real(Complex, _RealLike): def __lt__(self, other) -> bool: ... @abstractmethod def __le__(self, other) -> bool: ... - def __complex__(self) -> complex: ... + def __complex__(self) -> ComplexInt: ... @property def real(self) -> _RealLike: ... @property diff --git a/stdlib/optparse.pyi b/stdlib/optparse.pyi index 35dfc54a9d49..710a51c19c41 100644 --- a/stdlib/optparse.pyi +++ b/stdlib/optparse.pyi @@ -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): diff --git a/stdlib/pydoc.pyi b/stdlib/pydoc.pyi index dd9a365dff0b..43e715eebab4 100644 --- a/stdlib/pydoc.pyi +++ b/stdlib/pydoc.pyi @@ -1,5 +1,5 @@ import sys -from _typeshed import OptExcInfo, StrPath, SupportsWrite, Unused +from _typeshed import ComplexInt, OptExcInfo, StrPath, SupportsWrite, Unused from abc import abstractmethod from builtins import list as _list # "list" conflicts with method name from collections.abc import Callable, Container, Mapping, MutableMapping @@ -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: ComplexInt) -> str: ... + def repr_string(self, x: str, level: ComplexInt) -> str: ... + def repr_str(self, x: str, level: ComplexInt) -> str: ... + def repr_instance(self, x: object, level: ComplexInt) -> str: ... + def repr_unicode(self, x: AnyStr, level: ComplexInt) -> str: ... class HTMLDoc(Doc): _repr_instance: HTMLRepr @@ -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: ComplexInt) -> str: ... + def repr_string(self, x: str, level: ComplexInt) -> str: ... + def repr_str(self, x: str, level: ComplexInt) -> str: ... + def repr_instance(self, x: object, level: ComplexInt) -> str: ... class TextDoc(Doc): _repr_instance: TextRepr diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index b8b90a0934e5..57472fe10e51 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -5,7 +5,15 @@ import collections # ruff: ignore[unused-import] # pyright: ignore[reportUnuse import sys import typing_extensions from _collections_abc import dict_items, dict_keys, dict_values -from _typeshed import IdentityFunction, ReadableBuffer, SupportsGetItem, SupportsGetItemViewable, SupportsKeysAndGetItem, Viewable +from _typeshed import ( + ComplexInt, + IdentityFunction, + ReadableBuffer, + SupportsGetItem, + SupportsGetItemViewable, + SupportsKeysAndGetItem, + Viewable, +) from abc import ABCMeta, abstractmethod from re import Match as Match, Pattern as Pattern from types import ( @@ -500,7 +508,7 @@ class SupportsFloat(Protocol, metaclass=ABCMeta): class SupportsComplex(Protocol, metaclass=ABCMeta): __slots__ = () @abstractmethod - def __complex__(self) -> complex: ... + def __complex__(self) -> ComplexInt: ... @runtime_checkable class SupportsBytes(Protocol, metaclass=ABCMeta): diff --git a/stdlib/typing_extensions.pyi b/stdlib/typing_extensions.pyi index 49ddbc2f24bf..d2cadb4d4c10 100644 --- a/stdlib/typing_extensions.pyi +++ b/stdlib/typing_extensions.pyi @@ -2,7 +2,7 @@ import abc import enum import sys from _collections_abc import dict_items, dict_keys, dict_values -from _typeshed import AnnotationForm, IdentityFunction, Incomplete, Unused +from _typeshed import AnnotationForm, ComplexInt, IdentityFunction, Incomplete, Unused from collections.abc import ( AsyncGenerator as AsyncGenerator, AsyncIterable as AsyncIterable, @@ -413,7 +413,7 @@ else: class SupportsComplex(Protocol, metaclass=abc.ABCMeta): __slots__ = () @abc.abstractmethod - def __complex__(self) -> complex: ... + def __complex__(self) -> ComplexInt: ... @runtime_checkable class SupportsBytes(Protocol, metaclass=abc.ABCMeta): diff --git a/stubs/PyYAML/yaml/constructor.pyi b/stubs/PyYAML/yaml/constructor.pyi index 96d6661cbb70..ace367895435 100644 --- a/stubs/PyYAML/yaml/constructor.pyi +++ b/stubs/PyYAML/yaml/constructor.pyi @@ -1,4 +1,4 @@ -from _typeshed import Incomplete +from _typeshed import ComplexInt, Incomplete from collections.abc import Callable, Generator, Hashable from datetime import date from re import Pattern @@ -72,7 +72,7 @@ class FullConstructor(SafeConstructor): def construct_python_unicode(self, node) -> str: ... def construct_python_bytes(self, node) -> bytes: ... def construct_python_long(self, node) -> int: ... - def construct_python_complex(self, node) -> complex: ... + def construct_python_complex(self, node) -> ComplexInt: ... def construct_python_tuple(self, node) -> tuple[Incomplete, ...]: ... def find_python_module(self, name: str, mark, unsafe: bool = False) -> ModuleType: ... def find_python_name(self, name: str, mark, unsafe: bool = False): ... diff --git a/stubs/PyYAML/yaml/representer.pyi b/stubs/PyYAML/yaml/representer.pyi index 38255a636d49..06be71d6bd0d 100644 --- a/stubs/PyYAML/yaml/representer.pyi +++ b/stubs/PyYAML/yaml/representer.pyi @@ -1,5 +1,5 @@ import datetime -from _typeshed import Incomplete, ReadableBuffer, SupportsItems +from _typeshed import ComplexInt, Incomplete, ReadableBuffer, SupportsItems from collections.abc import Callable, Iterable, Mapping from types import BuiltinFunctionType, FunctionType, ModuleType from typing import ClassVar, TypeVar @@ -58,7 +58,7 @@ class SafeRepresenter(BaseRepresenter): def represent_undefined(self, data) -> Never: ... class Representer(SafeRepresenter): - def represent_complex(self, data: complex) -> ScalarNode: ... + def represent_complex(self, data: ComplexInt) -> ScalarNode: ... def represent_tuple(self, data: Iterable[Incomplete]) -> SequenceNode: ... def represent_name(self, data: BuiltinFunctionType | FunctionType) -> ScalarNode: ... def represent_module(self, data: ModuleType) -> ScalarNode: ... diff --git a/stubs/cffi/_cffi_backend.pyi b/stubs/cffi/_cffi_backend.pyi index 27c2f4d6cf00..72afe647abbc 100644 --- a/stubs/cffi/_cffi_backend.pyi +++ b/stubs/cffi/_cffi_backend.pyi @@ -1,6 +1,6 @@ import sys import types -from _typeshed import Incomplete, ReadableBuffer, WriteableBuffer +from _typeshed import ComplexInt, Incomplete, ReadableBuffer, WriteableBuffer from collections.abc import Callable, Hashable from typing import Any, ClassVar, Literal, Protocol, SupportsIndex, TypeAlias, TypeVar, final, overload, type_check_only from typing_extensions import Self, disjoint_base @@ -65,7 +65,7 @@ class _CDataBase: def __add__(self, other, /): ... def __bool__(self) -> bool: ... def __call__(self, *args, **kwargs): ... - def __complex__(self) -> complex: ... + def __complex__(self) -> ComplexInt: ... def __delitem__(self, other, /) -> None: ... def __dir__(self): ... def __enter__(self) -> Self: ... diff --git a/stubs/pyasn1/pyasn1/type/univ.pyi b/stubs/pyasn1/pyasn1/type/univ.pyi index ad2a65391381..2ab94666ca85 100644 --- a/stubs/pyasn1/pyasn1/type/univ.pyi +++ b/stubs/pyasn1/pyasn1/type/univ.pyi @@ -1,4 +1,4 @@ -from _typeshed import ConvertibleToInt, Incomplete, SupportsRichComparison +from _typeshed import ComplexInt, ConvertibleToInt, Incomplete, SupportsRichComparison from collections.abc import Callable, Generator from typing_extensions import Self @@ -52,7 +52,7 @@ class Integer(base.SimpleAsn1Type): def __mod__(self, value): ... def __rmod__(self, value): ... # Accepts everything builtins.pow does - def __pow__(self, value: complex, modulo: int | None = None) -> Self: ... + def __pow__(self, value: ComplexInt, modulo: int | None = None) -> Self: ... def __rpow__(self, value): ... def __floordiv__(self, value): ... def __rfloordiv__(self, value): ... @@ -206,7 +206,7 @@ class Real(base.SimpleAsn1Type): def __mod__(self, value): ... def __rmod__(self, value): ... # Accepts everything builtins.pow with a float base does - def __pow__(self, value: complex, modulo: int | None = None) -> Self: ... + def __pow__(self, value: ComplexInt, modulo: int | None = None) -> Self: ... def __rpow__(self, value): ... def __truediv__(self, value): ... def __rtruediv__(self, value): ... diff --git a/stubs/seaborn/seaborn/_core/typing.pyi b/stubs/seaborn/seaborn/_core/typing.pyi index c114bdf8f09f..04ec4857bfd0 100644 --- a/stubs/seaborn/seaborn/_core/typing.pyi +++ b/stubs/seaborn/seaborn/_core/typing.pyi @@ -1,4 +1,4 @@ -from _typeshed import Incomplete +from _typeshed import ComplexInt, Incomplete from collections.abc import Iterable, Mapping from datetime import date, datetime, timedelta from typing import Any, Protocol, TypeAlias, type_check_only @@ -11,7 +11,7 @@ from pandas import DataFrame, Index, Series, Timedelta, Timestamp class SupportsDataFrame(Protocol): def __dataframe__(self, nan_as_null: bool = ..., allow_copy: bool = ...): ... -ColumnName: TypeAlias = str | bytes | date | datetime | timedelta | bool | complex | Timestamp | Timedelta +ColumnName: TypeAlias = str | bytes | date | datetime | timedelta | bool | ComplexInt | Timestamp | Timedelta Vector: TypeAlias = Series[Any] | Index[Any] | ndarray[Any, Any] VariableSpec: TypeAlias = ColumnName | Vector | None VariableSpecList: TypeAlias = list[VariableSpec] | Index[Any] | None diff --git a/stubs/seaborn/seaborn/utils.pyi b/stubs/seaborn/seaborn/utils.pyi index 66859f2188a2..3255395e05b5 100644 --- a/stubs/seaborn/seaborn/utils.pyi +++ b/stubs/seaborn/seaborn/utils.pyi @@ -1,5 +1,5 @@ import datetime as dt -from _typeshed import Incomplete, SupportsGetItem +from _typeshed import ComplexInt, Incomplete, SupportsGetItem from collections.abc import Callable, Iterable, Mapping, Sequence from typing import Any, Literal, SupportsIndex, TypeAlias, TypeVar, overload from typing_extensions import deprecated @@ -41,7 +41,7 @@ _Seed: TypeAlias = int | np.random.Generator | np.random.RandomState # noqa: Y0 _Scalar: TypeAlias = ( # numeric float - | complex + | ComplexInt | np.number[Any] # dates | dt.date From f61ff0ac2ce0f77764f2dda8dfe24c8868f5cc87 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Mon, 9 Nov 2026 18:46:46 +0100 Subject: [PATCH 2/6] Replace `ComplexInt` in `fractions.pyi` Should fix CI --- stdlib/fractions.pyi | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/stdlib/fractions.pyi b/stdlib/fractions.pyi index ddb887cb89bf..42947f2e2266 100644 --- a/stdlib/fractions.pyi +++ b/stdlib/fractions.pyi @@ -1,5 +1,4 @@ import sys -from _typeshed import ComplexInt from collections.abc import Callable from decimal import Decimal from numbers import Rational, Real @@ -44,56 +43,56 @@ class Fraction(Rational): @overload def __add__(a, b: float) -> float: ... @overload - def __add__(a, b: ComplexInt) -> ComplexInt: ... + def __add__(a, b: complex) -> complex: ... @overload def __radd__(b, a: int | Fraction) -> Fraction: ... @overload def __radd__(b, a: float) -> float: ... @overload - def __radd__(b, a: ComplexInt) -> ComplexInt: ... + def __radd__(b, a: complex) -> complex: ... @overload def __sub__(a, b: int | Fraction) -> Fraction: ... @overload def __sub__(a, b: float) -> float: ... @overload - def __sub__(a, b: ComplexInt) -> ComplexInt: ... + def __sub__(a, b: complex) -> complex: ... @overload def __rsub__(b, a: int | Fraction) -> Fraction: ... @overload def __rsub__(b, a: float) -> float: ... @overload - def __rsub__(b, a: ComplexInt) -> ComplexInt: ... + def __rsub__(b, a: complex) -> complex: ... @overload def __mul__(a, b: int | Fraction) -> Fraction: ... @overload def __mul__(a, b: float) -> float: ... @overload - def __mul__(a, b: ComplexInt) -> ComplexInt: ... + def __mul__(a, b: complex) -> complex: ... @overload def __rmul__(b, a: int | Fraction) -> Fraction: ... @overload def __rmul__(b, a: float) -> float: ... @overload - def __rmul__(b, a: ComplexInt) -> ComplexInt: ... + def __rmul__(b, a: complex) -> complex: ... @overload def __truediv__(a, b: int | Fraction) -> Fraction: ... @overload def __truediv__(a, b: float) -> float: ... @overload - def __truediv__(a, b: ComplexInt) -> ComplexInt: ... + def __truediv__(a, b: complex) -> complex: ... @overload def __rtruediv__(b, a: int | Fraction) -> Fraction: ... @overload def __rtruediv__(b, a: float) -> float: ... @overload - def __rtruediv__(b, a: ComplexInt) -> ComplexInt: ... + def __rtruediv__(b, a: complex) -> complex: ... @overload def __floordiv__(a, b: int | Fraction) -> int: ... @@ -131,25 +130,25 @@ class Fraction(Rational): @overload def __pow__(a, b: float | Fraction, modulo: None = None) -> float: ... @overload - def __pow__(a, b: ComplexInt, modulo: None = None) -> ComplexInt: ... + def __pow__(a, b: complex, modulo: None = None) -> complex: ... else: @overload def __pow__(a, b: int) -> Fraction: ... @overload def __pow__(a, b: float | Fraction) -> float: ... @overload - def __pow__(a, b: ComplexInt) -> ComplexInt: ... + def __pow__(a, b: complex) -> complex: ... if sys.version_info >= (3, 14): @overload def __rpow__(b, a: float | Fraction, modulo: None = None) -> float: ... @overload - def __rpow__(b, a: ComplexInt, modulo: None = None) -> ComplexInt: ... + def __rpow__(b, a: complex, modulo: None = None) -> complex: ... else: @overload def __rpow__(b, a: float | Fraction) -> float: ... @overload - def __rpow__(b, a: ComplexInt) -> ComplexInt: ... + def __rpow__(b, a: complex) -> complex: ... def __pos__(a) -> Fraction: ... def __neg__(a) -> Fraction: ... From d8d372961d4878f903f6df4add693d2ed3a62f14 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Mon, 9 Nov 2026 18:59:53 +0100 Subject: [PATCH 3/6] Replace ComplexInt in builtins --- stdlib/builtins.pyi | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 86bf908ccfdf..41cfdaa432ec 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -6,7 +6,6 @@ import types from _collections_abc import dict_items, dict_keys, dict_values from _typeshed import ( AnnotationForm, - ComplexInt, ConvertibleToFloat, ConvertibleToInt, FileDescriptorOrPath, @@ -398,7 +397,7 @@ class float: @overload def __rpow__(self, value: _PositiveInteger, mod: None = None, /) -> float: ... @overload - def __rpow__(self, value: _NegativeInteger, mod: None = None, /) -> ComplexInt: ... + def __rpow__(self, value: _NegativeInteger, mod: None = None, /) -> complex: ... # Returning `complex` for the general case gives too many false-positive errors. @overload def __rpow__(self, value: float, mod: None = None, /) -> Any: ... @@ -447,27 +446,27 @@ class complex: def real(self) -> float: ... @property def imag(self) -> float: ... - def conjugate(self) -> ComplexInt: ... - def __add__(self, value: ComplexInt, /) -> ComplexInt: ... - def __sub__(self, value: ComplexInt, /) -> ComplexInt: ... - def __mul__(self, value: ComplexInt, /) -> ComplexInt: ... - def __pow__(self, value: ComplexInt, mod: None = None, /) -> ComplexInt: ... - def __truediv__(self, value: ComplexInt, /) -> ComplexInt: ... - def __radd__(self, value: ComplexInt, /) -> ComplexInt: ... - def __rsub__(self, value: ComplexInt, /) -> ComplexInt: ... - def __rmul__(self, value: ComplexInt, /) -> ComplexInt: ... - def __rpow__(self, value: ComplexInt, mod: None = None, /) -> ComplexInt: ... - def __rtruediv__(self, value: ComplexInt, /) -> ComplexInt: ... + def conjugate(self) -> 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) -> ComplexInt: ... - def __pos__(self) -> ComplexInt: ... + def __neg__(self) -> complex: ... + def __pos__(self) -> complex: ... def __abs__(self) -> float: ... def __hash__(self) -> int: ... def __bool__(self) -> bool: ... def __format__(self, format_spec: str, /) -> str: ... if sys.version_info >= (3, 11): - def __complex__(self) -> ComplexInt: ... + def __complex__(self) -> complex: ... if sys.version_info >= (3, 14): @classmethod def from_number(cls, number: complex | float | int | SupportsComplex | SupportsFloat | SupportsIndex, /) -> Self: ... @@ -2178,7 +2177,7 @@ def pow(base: int, exp: int, mod: None = None) -> Any: ... @overload def pow(base: _PositiveInteger, exp: float, mod: None = None) -> float: ... @overload -def pow(base: _NegativeInteger, exp: float, mod: None = None) -> ComplexInt: ... +def pow(base: _NegativeInteger, exp: float, mod: None = None) -> complex: ... @overload def pow(base: float, exp: int, mod: None = None) -> float: ... @@ -2186,9 +2185,9 @@ 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: ComplexInt | _SupportsSomeKindOfPow, mod: None = None) -> Any: ... +def pow(base: float, exp: complex | float | int | _SupportsSomeKindOfPow, mod: None = None) -> Any: ... @overload -def pow(base: ComplexInt, exp: ComplexInt | _SupportsSomeKindOfPow, mod: None = None) -> ComplexInt: ... +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 @@ -2196,9 +2195,9 @@ def pow(base: _SupportsPow3NoneOnly[_E_contra, _T_co], exp: _E_contra, mod: None @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: ComplexInt, mod: None = None) -> ComplexInt: ... +def pow(base: _SupportsSomeKindOfPow, exp: complex, mod: None = None) -> complex: ... quit: _sitebuiltins.Quitter From d3d95bc2aada31b03c7084968f69d497c8137d2c Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Mon, 9 Nov 2026 19:19:01 +0100 Subject: [PATCH 4/6] Replace remaining instances; remove type alias --- stdlib/_typeshed/__init__.pyi | 7 ++--- stdlib/ast.pyi | 4 +-- stdlib/cmath.pyi | 39 +++++++++++++------------- stdlib/collections/__init__.pyi | 4 +-- stdlib/ctypes/__init__.pyi | 8 +++--- stdlib/decimal.pyi | 3 +- stdlib/functools.pyi | 2 +- stdlib/numbers.pyi | 5 ++-- stdlib/pydoc.pyi | 20 ++++++------- stdlib/typing.pyi | 12 ++------ stdlib/typing_extensions.pyi | 4 +-- stubs/PyYAML/yaml/constructor.pyi | 4 +-- stubs/PyYAML/yaml/representer.pyi | 4 +-- stubs/cffi/_cffi_backend.pyi | 4 +-- stubs/pyasn1/pyasn1/type/univ.pyi | 6 ++-- stubs/seaborn/seaborn/_core/typing.pyi | 4 +-- stubs/seaborn/seaborn/utils.pyi | 7 +++-- 17 files changed, 63 insertions(+), 74 deletions(-) diff --git a/stdlib/_typeshed/__init__.pyi b/stdlib/_typeshed/__init__.pyi index fa6ef8150e3a..f42be80abdc0 100644 --- a/stdlib/_typeshed/__init__.pyi +++ b/stdlib/_typeshed/__init__.pyi @@ -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. diff --git a/stdlib/ast.pyi b/stdlib/ast.pyi index 72d879892264..000f84093604 100644 --- a/stdlib/ast.pyi +++ b/stdlib/ast.pyi @@ -8,7 +8,7 @@ from _ast import ( PyCF_ONLY_AST as PyCF_ONLY_AST, PyCF_TYPE_COMMENTS as PyCF_TYPE_COMMENTS, ) -from _typeshed import ComplexInt, ReadableBuffer, Unused +from _typeshed import ReadableBuffer, Unused from collections.abc import Iterable, Iterator, Sequence from types import EllipsisType from typing import Any, ClassVar, Generic, Literal, TypedDict, TypeVar as _TypeVar, overload, type_check_only @@ -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: ComplexInt, **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): diff --git a/stdlib/cmath.pyi b/stdlib/cmath.pyi index 6bda00988b46..36fedef8ce6e 100644 --- a/stdlib/cmath.pyi +++ b/stdlib/cmath.pyi @@ -1,37 +1,36 @@ -from _typeshed import ComplexInt from typing import Final, SupportsComplex, SupportsFloat, SupportsIndex, TypeAlias e: Final[float] pi: Final[float] inf: Final[float] -infj: Final[ComplexInt] +infj: Final[complex] nan: Final[float] -nanj: Final[ComplexInt] +nanj: Final[complex] tau: Final[float] _F: TypeAlias = SupportsIndex | SupportsFloat _C: TypeAlias = SupportsIndex | SupportsFloat | SupportsComplex | int | float | complex -def acos(z: _C, /) -> ComplexInt: ... -def acosh(z: _C, /) -> ComplexInt: ... -def asin(z: _C, /) -> ComplexInt: ... -def asinh(z: _C, /) -> ComplexInt: ... -def atan(z: _C, /) -> ComplexInt: ... -def atanh(z: _C, /) -> ComplexInt: ... -def cos(z: _C, /) -> ComplexInt: ... -def cosh(z: _C, /) -> ComplexInt: ... -def exp(z: _C, /) -> ComplexInt: ... +def acos(z: _C, /) -> complex: ... +def acosh(z: _C, /) -> complex: ... +def asin(z: _C, /) -> complex: ... +def asinh(z: _C, /) -> complex: ... +def atan(z: _C, /) -> complex: ... +def atanh(z: _C, /) -> complex: ... +def cos(z: _C, /) -> complex: ... +def cosh(z: _C, /) -> complex: ... +def exp(z: _C, /) -> complex: ... def isclose(a: _C, b: _C, *, rel_tol: SupportsFloat = 1e-09, abs_tol: SupportsFloat = 0.0) -> bool: ... def isinf(z: _C, /) -> bool: ... def isnan(z: _C, /) -> bool: ... -def log(z: _C, base: _C = ..., /) -> ComplexInt: ... -def log10(z: _C, /) -> ComplexInt: ... +def log(z: _C, base: _C = ..., /) -> complex: ... +def log10(z: _C, /) -> complex: ... def phase(z: _C, /) -> float: ... def polar(z: _C, /) -> tuple[float, float]: ... -def rect(r: _F, phi: _F, /) -> ComplexInt: ... -def sin(z: _C, /) -> ComplexInt: ... -def sinh(z: _C, /) -> ComplexInt: ... -def sqrt(z: _C, /) -> ComplexInt: ... -def tan(z: _C, /) -> ComplexInt: ... -def tanh(z: _C, /) -> ComplexInt: ... +def rect(r: _F, phi: _F, /) -> complex: ... +def sin(z: _C, /) -> complex: ... +def sinh(z: _C, /) -> complex: ... +def sqrt(z: _C, /) -> complex: ... +def tan(z: _C, /) -> complex: ... +def tanh(z: _C, /) -> complex: ... def isfinite(z: _C, /) -> bool: ... diff --git a/stdlib/collections/__init__.pyi b/stdlib/collections/__init__.pyi index becd37036825..bce72464fd75 100644 --- a/stdlib/collections/__init__.pyi +++ b/stdlib/collections/__init__.pyi @@ -1,6 +1,6 @@ import sys from _collections_abc import dict_items, dict_keys, dict_values -from _typeshed import ComplexInt, SupportsItems, SupportsKeysAndGetItem, SupportsRichComparison, SupportsRichComparisonT +from _typeshed import SupportsItems, SupportsKeysAndGetItem, SupportsRichComparison, SupportsRichComparisonT from collections.abc import ( Callable, ItemsView, @@ -176,7 +176,7 @@ class UserString(Sequence[UserString]): def __init__(self, seq: object) -> None: ... def __int__(self) -> int: ... def __float__(self) -> float: ... - def __complex__(self) -> ComplexInt: ... + def __complex__(self) -> complex: ... def __getnewargs__(self) -> tuple[str]: ... def __lt__(self, string: str | UserString) -> bool: ... def __le__(self, string: str | UserString) -> bool: ... diff --git a/stdlib/ctypes/__init__.pyi b/stdlib/ctypes/__init__.pyi index 9f9b418ec295..7d133506af93 100644 --- a/stdlib/ctypes/__init__.pyi +++ b/stdlib/ctypes/__init__.pyi @@ -23,7 +23,7 @@ from _ctypes import ( set_errno as set_errno, sizeof as sizeof, ) -from _typeshed import ComplexInt, StrPath, SupportsBool, SupportsLen +from _typeshed import StrPath, SupportsBool, SupportsLen from ctypes._endian import BigEndianStructure as BigEndianStructure, LittleEndianStructure as LittleEndianStructure from types import GenericAlias from typing import Any, ClassVar, Final, Generic, Literal, TypeAlias, TypeVar, overload, type_check_only @@ -333,7 +333,7 @@ if sys.version_info >= (3, 14) and sys.platform != "win32": # NOTE: currently (3.14.4) the `__ctype_{be,le}__` attributes of these complex types are missing at runtime: # https://github.com/python/cpython/issues/148464 - class c_double_complex(_SimpleCData[ComplexInt]): + class c_double_complex(_SimpleCData[complex]): if sys.version_info >= (3, 15): _type_: ClassVar[Literal["Zd"]] else: @@ -341,7 +341,7 @@ if sys.version_info >= (3, 14) and sys.platform != "win32": __ctype_be__: ClassVar[type[Self]] __ctype_le__: ClassVar[type[Self]] - class c_float_complex(_SimpleCData[ComplexInt]): + class c_float_complex(_SimpleCData[complex]): if sys.version_info >= (3, 15): _type_: ClassVar[Literal["Zf"]] else: @@ -349,7 +349,7 @@ if sys.version_info >= (3, 14) and sys.platform != "win32": __ctype_be__: ClassVar[type[Self]] __ctype_le__: ClassVar[type[Self]] - class c_longdouble_complex(_SimpleCData[ComplexInt]): + class c_longdouble_complex(_SimpleCData[complex]): if sys.version_info >= (3, 15): _type_: ClassVar[Literal["Zg"]] else: diff --git a/stdlib/decimal.pyi b/stdlib/decimal.pyi index 412a60c01129..f116603cf0f2 100644 --- a/stdlib/decimal.pyi +++ b/stdlib/decimal.pyi @@ -24,7 +24,6 @@ from _decimal import ( localcontext as localcontext, setcontext as setcontext, ) -from _typeshed import ComplexInt from collections.abc import Container, Sequence from types import TracebackType from typing import Any, ClassVar, Literal, NamedTuple, TypeAlias, final, overload, type_check_only @@ -118,7 +117,7 @@ class Decimal: @property def imag(self) -> Decimal: ... def conjugate(self) -> Decimal: ... - def __complex__(self) -> ComplexInt: ... + def __complex__(self) -> complex: ... @overload def __round__(self) -> int: ... diff --git a/stdlib/functools.pyi b/stdlib/functools.pyi index da44cbd042bd..25e75b4f18f0 100644 --- a/stdlib/functools.pyi +++ b/stdlib/functools.pyi @@ -233,7 +233,7 @@ class _SingleDispatchCallable(Generic[_T]): registry: types.MappingProxyType[Any, Callable[..., _T]] def dispatch(self, cls: Any) -> Callable[..., _T]: ... - # @fun.register(ComplexInt) + # @fun.register(complex | float | int) # def _(arg, verbose=False): ... @overload def register(self, cls: _RegType, func: None = None) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ... diff --git a/stdlib/numbers.pyi b/stdlib/numbers.pyi index c31791297ee6..434e52c4cac8 100644 --- a/stdlib/numbers.pyi +++ b/stdlib/numbers.pyi @@ -7,7 +7,6 @@ # (since type checkers don't see `complex` as a subtype of `numbers.Complex`, # nor `float` as a subtype of `numbers.Real`, etc.) -from _typeshed import ComplexInt from abc import ABCMeta, abstractmethod from typing import ClassVar, Literal, Protocol, overload, type_check_only @@ -71,7 +70,7 @@ class Number(metaclass=ABCMeta): class Complex(Number, _ComplexLike): __slots__ = () @abstractmethod - def __complex__(self) -> ComplexInt: ... + def __complex__(self) -> complex: ... def __bool__(self) -> bool: ... @property @abstractmethod @@ -143,7 +142,7 @@ class Real(Complex, _RealLike): def __lt__(self, other) -> bool: ... @abstractmethod def __le__(self, other) -> bool: ... - def __complex__(self) -> ComplexInt: ... + def __complex__(self) -> complex: ... @property def real(self) -> _RealLike: ... @property diff --git a/stdlib/pydoc.pyi b/stdlib/pydoc.pyi index 43e715eebab4..9943aaa5e0d8 100644 --- a/stdlib/pydoc.pyi +++ b/stdlib/pydoc.pyi @@ -1,5 +1,5 @@ import sys -from _typeshed import ComplexInt, OptExcInfo, StrPath, SupportsWrite, Unused +from _typeshed import OptExcInfo, StrPath, SupportsWrite, Unused from abc import abstractmethod from builtins import list as _list # "list" conflicts with method name from collections.abc import Callable, Container, Mapping, MutableMapping @@ -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: ComplexInt) -> str: ... - def repr_string(self, x: str, level: ComplexInt) -> str: ... - def repr_str(self, x: str, level: ComplexInt) -> str: ... - def repr_instance(self, x: object, level: ComplexInt) -> str: ... - def repr_unicode(self, x: AnyStr, level: ComplexInt) -> 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 @@ -190,10 +190,10 @@ class HTMLDoc(Doc): class TextRepr(Repr): def __init__(self) -> None: ... - def repr1(self, x: object, level: ComplexInt) -> str: ... - def repr_string(self, x: str, level: ComplexInt) -> str: ... - def repr_str(self, x: str, level: ComplexInt) -> str: ... - def repr_instance(self, x: object, level: ComplexInt) -> 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 diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index 57472fe10e51..b8b90a0934e5 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -5,15 +5,7 @@ import collections # ruff: ignore[unused-import] # pyright: ignore[reportUnuse import sys import typing_extensions from _collections_abc import dict_items, dict_keys, dict_values -from _typeshed import ( - ComplexInt, - IdentityFunction, - ReadableBuffer, - SupportsGetItem, - SupportsGetItemViewable, - SupportsKeysAndGetItem, - Viewable, -) +from _typeshed import IdentityFunction, ReadableBuffer, SupportsGetItem, SupportsGetItemViewable, SupportsKeysAndGetItem, Viewable from abc import ABCMeta, abstractmethod from re import Match as Match, Pattern as Pattern from types import ( @@ -508,7 +500,7 @@ class SupportsFloat(Protocol, metaclass=ABCMeta): class SupportsComplex(Protocol, metaclass=ABCMeta): __slots__ = () @abstractmethod - def __complex__(self) -> ComplexInt: ... + def __complex__(self) -> complex: ... @runtime_checkable class SupportsBytes(Protocol, metaclass=ABCMeta): diff --git a/stdlib/typing_extensions.pyi b/stdlib/typing_extensions.pyi index d2cadb4d4c10..49ddbc2f24bf 100644 --- a/stdlib/typing_extensions.pyi +++ b/stdlib/typing_extensions.pyi @@ -2,7 +2,7 @@ import abc import enum import sys from _collections_abc import dict_items, dict_keys, dict_values -from _typeshed import AnnotationForm, ComplexInt, IdentityFunction, Incomplete, Unused +from _typeshed import AnnotationForm, IdentityFunction, Incomplete, Unused from collections.abc import ( AsyncGenerator as AsyncGenerator, AsyncIterable as AsyncIterable, @@ -413,7 +413,7 @@ else: class SupportsComplex(Protocol, metaclass=abc.ABCMeta): __slots__ = () @abc.abstractmethod - def __complex__(self) -> ComplexInt: ... + def __complex__(self) -> complex: ... @runtime_checkable class SupportsBytes(Protocol, metaclass=abc.ABCMeta): diff --git a/stubs/PyYAML/yaml/constructor.pyi b/stubs/PyYAML/yaml/constructor.pyi index ace367895435..96d6661cbb70 100644 --- a/stubs/PyYAML/yaml/constructor.pyi +++ b/stubs/PyYAML/yaml/constructor.pyi @@ -1,4 +1,4 @@ -from _typeshed import ComplexInt, Incomplete +from _typeshed import Incomplete from collections.abc import Callable, Generator, Hashable from datetime import date from re import Pattern @@ -72,7 +72,7 @@ class FullConstructor(SafeConstructor): def construct_python_unicode(self, node) -> str: ... def construct_python_bytes(self, node) -> bytes: ... def construct_python_long(self, node) -> int: ... - def construct_python_complex(self, node) -> ComplexInt: ... + def construct_python_complex(self, node) -> complex: ... def construct_python_tuple(self, node) -> tuple[Incomplete, ...]: ... def find_python_module(self, name: str, mark, unsafe: bool = False) -> ModuleType: ... def find_python_name(self, name: str, mark, unsafe: bool = False): ... diff --git a/stubs/PyYAML/yaml/representer.pyi b/stubs/PyYAML/yaml/representer.pyi index 06be71d6bd0d..9e1dd7c4d53d 100644 --- a/stubs/PyYAML/yaml/representer.pyi +++ b/stubs/PyYAML/yaml/representer.pyi @@ -1,5 +1,5 @@ import datetime -from _typeshed import ComplexInt, Incomplete, ReadableBuffer, SupportsItems +from _typeshed import Incomplete, ReadableBuffer, SupportsItems from collections.abc import Callable, Iterable, Mapping from types import BuiltinFunctionType, FunctionType, ModuleType from typing import ClassVar, TypeVar @@ -58,7 +58,7 @@ class SafeRepresenter(BaseRepresenter): def represent_undefined(self, data) -> Never: ... class Representer(SafeRepresenter): - def represent_complex(self, data: ComplexInt) -> ScalarNode: ... + def represent_complex(self, data: complex | float | int) -> ScalarNode: ... def represent_tuple(self, data: Iterable[Incomplete]) -> SequenceNode: ... def represent_name(self, data: BuiltinFunctionType | FunctionType) -> ScalarNode: ... def represent_module(self, data: ModuleType) -> ScalarNode: ... diff --git a/stubs/cffi/_cffi_backend.pyi b/stubs/cffi/_cffi_backend.pyi index 72afe647abbc..27c2f4d6cf00 100644 --- a/stubs/cffi/_cffi_backend.pyi +++ b/stubs/cffi/_cffi_backend.pyi @@ -1,6 +1,6 @@ import sys import types -from _typeshed import ComplexInt, Incomplete, ReadableBuffer, WriteableBuffer +from _typeshed import Incomplete, ReadableBuffer, WriteableBuffer from collections.abc import Callable, Hashable from typing import Any, ClassVar, Literal, Protocol, SupportsIndex, TypeAlias, TypeVar, final, overload, type_check_only from typing_extensions import Self, disjoint_base @@ -65,7 +65,7 @@ class _CDataBase: def __add__(self, other, /): ... def __bool__(self) -> bool: ... def __call__(self, *args, **kwargs): ... - def __complex__(self) -> ComplexInt: ... + def __complex__(self) -> complex: ... def __delitem__(self, other, /) -> None: ... def __dir__(self): ... def __enter__(self) -> Self: ... diff --git a/stubs/pyasn1/pyasn1/type/univ.pyi b/stubs/pyasn1/pyasn1/type/univ.pyi index 2ab94666ca85..dd3b50a733c3 100644 --- a/stubs/pyasn1/pyasn1/type/univ.pyi +++ b/stubs/pyasn1/pyasn1/type/univ.pyi @@ -1,4 +1,4 @@ -from _typeshed import ComplexInt, ConvertibleToInt, Incomplete, SupportsRichComparison +from _typeshed import ConvertibleToInt, Incomplete, SupportsRichComparison from collections.abc import Callable, Generator from typing_extensions import Self @@ -52,7 +52,7 @@ class Integer(base.SimpleAsn1Type): def __mod__(self, value): ... def __rmod__(self, value): ... # Accepts everything builtins.pow does - def __pow__(self, value: ComplexInt, modulo: int | None = None) -> Self: ... + def __pow__(self, value: complex | float | int, modulo: int | None = None) -> Self: ... def __rpow__(self, value): ... def __floordiv__(self, value): ... def __rfloordiv__(self, value): ... @@ -206,7 +206,7 @@ class Real(base.SimpleAsn1Type): def __mod__(self, value): ... def __rmod__(self, value): ... # Accepts everything builtins.pow with a float base does - def __pow__(self, value: ComplexInt, modulo: int | None = None) -> Self: ... + def __pow__(self, value: complex | float | int, modulo: int | None = None) -> Self: ... def __rpow__(self, value): ... def __truediv__(self, value): ... def __rtruediv__(self, value): ... diff --git a/stubs/seaborn/seaborn/_core/typing.pyi b/stubs/seaborn/seaborn/_core/typing.pyi index 04ec4857bfd0..c1fefb365b75 100644 --- a/stubs/seaborn/seaborn/_core/typing.pyi +++ b/stubs/seaborn/seaborn/_core/typing.pyi @@ -1,4 +1,4 @@ -from _typeshed import ComplexInt, Incomplete +from _typeshed import Incomplete from collections.abc import Iterable, Mapping from datetime import date, datetime, timedelta from typing import Any, Protocol, TypeAlias, type_check_only @@ -11,7 +11,7 @@ from pandas import DataFrame, Index, Series, Timedelta, Timestamp class SupportsDataFrame(Protocol): def __dataframe__(self, nan_as_null: bool = ..., allow_copy: bool = ...): ... -ColumnName: TypeAlias = str | bytes | date | datetime | timedelta | bool | ComplexInt | Timestamp | Timedelta +ColumnName: TypeAlias = str | bytes | date | datetime | timedelta | bool | complex | float | int | Timestamp | Timedelta Vector: TypeAlias = Series[Any] | Index[Any] | ndarray[Any, Any] VariableSpec: TypeAlias = ColumnName | Vector | None VariableSpecList: TypeAlias = list[VariableSpec] | Index[Any] | None diff --git a/stubs/seaborn/seaborn/utils.pyi b/stubs/seaborn/seaborn/utils.pyi index 3255395e05b5..5a0345f1088c 100644 --- a/stubs/seaborn/seaborn/utils.pyi +++ b/stubs/seaborn/seaborn/utils.pyi @@ -1,5 +1,5 @@ import datetime as dt -from _typeshed import ComplexInt, Incomplete, SupportsGetItem +from _typeshed import Incomplete, SupportsGetItem from collections.abc import Callable, Iterable, Mapping, Sequence from typing import Any, Literal, SupportsIndex, TypeAlias, TypeVar, overload from typing_extensions import deprecated @@ -40,8 +40,9 @@ _Palette: TypeAlias = str | Sequence[ColorType] | Mapping[Any, ColorType] # noq _Seed: TypeAlias = int | np.random.Generator | np.random.RandomState # noqa: Y047 _Scalar: TypeAlias = ( # numeric - float - | ComplexInt + complex + | float + | int | np.number[Any] # dates | dt.date From e01ad47bd95cf308aff1022789977d928e56bdc7 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Mon, 9 Nov 2026 19:33:25 +0100 Subject: [PATCH 5/6] Remove redundant types --- stdlib/builtins.pyi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 41cfdaa432ec..c764452d65d3 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -436,8 +436,8 @@ class complex: @overload def __new__( cls, - real: complex | float | int | SupportsComplex | SupportsFloat | SupportsIndex = 0, - imag: complex | float | int | SupportsFloat | SupportsIndex = 0, + real: complex | SupportsComplex | SupportsFloat | SupportsIndex = 0, + imag: complex | SupportsFloat | SupportsIndex = 0, ) -> Self: ... @overload def __new__(cls, real: str | SupportsComplex | SupportsFloat | SupportsIndex | complex | float | int) -> Self: ... @@ -469,7 +469,7 @@ class complex: def __complex__(self) -> complex: ... if sys.version_info >= (3, 14): @classmethod - def from_number(cls, number: complex | float | int | SupportsComplex | SupportsFloat | SupportsIndex, /) -> Self: ... + def from_number(cls, number: SupportsComplex | SupportsFloat | SupportsIndex, /) -> Self: ... @type_check_only class _FormatMapMapping(Protocol): From 817f1a5eff10150f63068275a501018b20df3845 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Mon, 9 Nov 2026 19:34:05 +0100 Subject: [PATCH 6/6] Remove a redundant float as well --- stdlib/builtins.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index c764452d65d3..d9f225f1bc00 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -428,7 +428,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: