Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b993718

Browse files
authored
Correct Fraction.__new__ typing for subclasses. (#5251)
Co-authored-by: David Barker <[email protected]>
1 parent f1cd416 commit b993718

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

stdlib/fractions.pyi

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import sys
22
from decimal import Decimal
33
from numbers import Integral, Rational, Real
4-
from typing import Optional, Tuple, Union, overload
4+
from typing import Optional, Tuple, Type, TypeVar, Union, overload
55
from typing_extensions import Literal
66

77
_ComparableNum = Union[int, float, Decimal, Real]
8+
_T = TypeVar("_T")
89

910
if sys.version_info < (3, 9):
1011
@overload
@@ -19,10 +20,14 @@ if sys.version_info < (3, 9):
1920
class Fraction(Rational):
2021
@overload
2122
def __new__(
22-
cls, numerator: Union[int, Rational] = ..., denominator: Optional[Union[int, Rational]] = ..., *, _normalize: bool = ...
23-
) -> Fraction: ...
24-
@overload
25-
def __new__(cls, __value: Union[float, Decimal, str], *, _normalize: bool = ...) -> Fraction: ...
23+
cls: Type[_T],
24+
numerator: Union[int, Rational] = ...,
25+
denominator: Optional[Union[int, Rational]] = ...,
26+
*,
27+
_normalize: bool = ...,
28+
) -> _T: ...
29+
@overload
30+
def __new__(cls: Type[_T], __value: Union[float, Decimal, str], *, _normalize: bool = ...) -> _T: ...
2631
@classmethod
2732
def from_float(cls, f: float) -> Fraction: ...
2833
@classmethod

0 commit comments

Comments
 (0)