From b9937184ed116e85c547b287cbaafa76fcff7a30 Mon Sep 17 00:00:00 2001 From: David Barker Date: Tue, 27 Apr 2021 09:15:54 +0100 Subject: [PATCH] Correct Fraction.__new__ typing for subclasses. (#5251) Co-authored-by: David Barker --- stdlib/fractions.pyi | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/stdlib/fractions.pyi b/stdlib/fractions.pyi index dd9c77ed3..75cfa48a1 100644 --- a/stdlib/fractions.pyi +++ b/stdlib/fractions.pyi @@ -1,10 +1,11 @@ import sys from decimal import Decimal from numbers import Integral, Rational, Real -from typing import Optional, Tuple, Union, overload +from typing import Optional, Tuple, Type, TypeVar, Union, overload from typing_extensions import Literal _ComparableNum = Union[int, float, Decimal, Real] +_T = TypeVar("_T") if sys.version_info < (3, 9): @overload @@ -19,10 +20,14 @@ if sys.version_info < (3, 9): class Fraction(Rational): @overload def __new__( - cls, numerator: Union[int, Rational] = ..., denominator: Optional[Union[int, Rational]] = ..., *, _normalize: bool = ... - ) -> Fraction: ... + cls: Type[_T], + numerator: Union[int, Rational] = ..., + denominator: Optional[Union[int, Rational]] = ..., + *, + _normalize: bool = ..., + ) -> _T: ... @overload - def __new__(cls, __value: Union[float, Decimal, str], *, _normalize: bool = ...) -> Fraction: ... + def __new__(cls: Type[_T], __value: Union[float, Decimal, str], *, _normalize: bool = ...) -> _T: ... @classmethod def from_float(cls, f: float) -> Fraction: ... @classmethod