Use typing_extensions.Self in the stdlib (#9694)

This commit is contained in:
Alex Waygood
2023-02-09 09:12:13 +00:00
committed by GitHub
parent 10086c06a1
commit 9ed39d8796
98 changed files with 627 additions and 654 deletions

View File

@@ -1,10 +1,9 @@
import sys
from _typeshed import Self
from collections.abc import Callable
from decimal import Decimal
from numbers import Integral, Rational, Real
from typing import Any, overload
from typing_extensions import Literal, SupportsIndex, TypeAlias
from typing_extensions import Literal, Self, SupportsIndex, TypeAlias
_ComparableNum: TypeAlias = int | float | Decimal | Real
@@ -24,14 +23,14 @@ else:
class Fraction(Rational):
@overload
def __new__(
cls: type[Self], numerator: int | Rational = 0, denominator: int | Rational | None = None, *, _normalize: bool = True
cls, numerator: int | Rational = 0, denominator: int | Rational | None = None, *, _normalize: bool = True
) -> Self: ...
@overload
def __new__(cls: type[Self], __value: float | Decimal | str, *, _normalize: bool = True) -> Self: ...
def __new__(cls, __value: float | Decimal | str, *, _normalize: bool = True) -> Self: ...
@classmethod
def from_float(cls: type[Self], f: float) -> Self: ...
def from_float(cls, f: float) -> Self: ...
@classmethod
def from_decimal(cls: type[Self], dec: Decimal) -> Self: ...
def from_decimal(cls, dec: Decimal) -> Self: ...
def limit_denominator(self, max_denominator: int = 1000000) -> Fraction: ...
if sys.version_info >= (3, 8):
def as_integer_ratio(self) -> tuple[int, int]: ...
@@ -139,8 +138,8 @@ class Fraction(Rational):
def __le__(a, b: _ComparableNum) -> bool: ...
def __ge__(a, b: _ComparableNum) -> bool: ...
def __bool__(a) -> bool: ...
def __copy__(self: Self) -> Self: ...
def __deepcopy__(self: Self, memo: Any) -> Self: ...
def __copy__(self) -> Self: ...
def __deepcopy__(self, memo: Any) -> Self: ...
if sys.version_info >= (3, 11):
def __int__(a, _index: Callable[[SupportsIndex], int] = ...) -> int: ...
# Not actually defined within fractions.py, but provides more useful