Fraction.__new__ now accepts anything with .as_integer_ratio() (#12994)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
InSyncandAlex Waygood authored and GitHub committed 2024-11-12 12:57:54 +00:00
1 parent 074cef02a5
commit 986e9e3830
1 file changed
+9 -1
+9 -1
View File
@@ -2,7 +2,7 @@ import sys
from collections.abc import Callable
from decimal import Decimal
from numbers import Integral, Rational, Real
from typing import Any, Literal, SupportsIndex, overload
from typing import Any, Literal, Protocol, SupportsIndex, overload
from typing_extensions import Self, TypeAlias
_ComparableNum: TypeAlias = int | float | Decimal | Real
@@ -20,11 +20,19 @@ else:
@overload
def gcd(a: Integral, b: Integral) -> Integral: ...
class _ConvertibleToIntegerRatio(Protocol):
def as_integer_ratio(self) -> tuple[int | Rational, int | Rational]: ...
class Fraction(Rational):
@overload
def __new__(cls, numerator: int | Rational = 0, denominator: int | Rational | None = None) -> Self: ...
@overload
def __new__(cls, value: float | Decimal | str, /) -> Self: ...
if sys.version_info >= (3, 14):
@overload
def __new__(cls, value: _ConvertibleToIntegerRatio) -> Self: ...
@classmethod
def from_float(cls, f: float) -> Self: ...
@classmethod