mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-07 12:44:28 +08:00
Fraction.__new__ now accepts anything with .as_integer_ratio() (#12994)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user