Skip to content

Commit 567b488

Browse files
authored
Python 3.14: bump fractions stubs (#14215)
1 parent 2a742fd commit 567b488

File tree

3 files changed

+37
-16
lines changed

3 files changed

+37
-16
lines changed

stdlib/@tests/stubtest_allowlists/py314.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ compression.gzip.GzipFile.readinto
99
compression.gzip.GzipFile.readinto1
1010
compression.gzip.GzipFile.readinto1
1111
compression.gzip.compress
12-
fractions.Fraction.__pow__
13-
fractions.Fraction.__rpow__
1412
gzip.GzipFile.readinto
1513
gzip.GzipFile.readinto1
1614
gzip.compress

stdlib/@tests/test_cases/builtins/check_pow.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import sys
34
from decimal import Decimal
45
from fractions import Fraction
56
from typing import Any, Literal
@@ -47,9 +48,6 @@
4748
assert_type(complex(6) ** 6.2, complex)
4849
assert_type(pow(complex(9), 7.3, None), complex)
4950

50-
# pyright infers Fraction | float | complex, while mypy infers Fraction.
51-
# This is probably because of differences in @overload handling.
52-
assert_type(pow(Fraction(), 4, None), Fraction) # pyright: ignore[reportAssertTypeFailure]
5351
assert_type(Fraction() ** 4, Fraction)
5452

5553
assert_type(pow(Fraction(3, 7), complex(1, 8)), complex)
@@ -85,12 +83,22 @@
8583
# See #7046 -- float for a positive 1st arg, complex otherwise
8684
assert_type((-95) ** 8.42, Any)
8785

86+
# Fraction.__pow__/__rpow__ with modulo parameter
87+
# With the None parameter, we get the correct type, but with a non-None parameter, we receive TypeError
88+
if sys.version_info >= (3, 14):
89+
# pyright infers Fraction | float | complex, while mypy infers Fraction.
90+
# This is probably because of differences in @overload handling.
91+
assert_type(pow(Fraction(3, 4), 2, None), Fraction) # pyright: ignore[reportAssertTypeFailure]
92+
# Non-none modulo should fail
93+
pow(Fraction(3, 4), 2, 1) # type: ignore[misc]
94+
else:
95+
pow(Fraction(), 5, 8) # type: ignore
96+
8897
# All of the following cases should fail a type-checker.
8998
pow(1.9, 4, 6) # type: ignore
9099
pow(4, 7, 4.32) # type: ignore
91100
pow(6.2, 5.9, 73) # type: ignore
92101
pow(complex(6), 6.2, 7) # type: ignore
93-
pow(Fraction(), 5, 8) # type: ignore
94102
Decimal("8.7") ** 3.14 # type: ignore
95103

96104
# TODO: This fails at runtime, but currently passes mypy and pyright:

stdlib/fractions.pyi

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,31 @@ class Fraction(Rational):
107107
def __rdivmod__(a, b: int | Fraction) -> tuple[int, Fraction]: ...
108108
@overload
109109
def __rdivmod__(a, b: float) -> tuple[float, Fraction]: ...
110-
@overload
111-
def __pow__(a, b: int) -> Fraction: ...
112-
@overload
113-
def __pow__(a, b: float | Fraction) -> float: ...
114-
@overload
115-
def __pow__(a, b: complex) -> complex: ...
116-
@overload
117-
def __rpow__(b, a: float | Fraction) -> float: ...
118-
@overload
119-
def __rpow__(b, a: complex) -> complex: ...
110+
if sys.version_info >= (3, 14):
111+
@overload
112+
def __pow__(a, b: int, modulo: None = None) -> Fraction: ...
113+
@overload
114+
def __pow__(a, b: float | Fraction, modulo: None = None) -> float: ...
115+
@overload
116+
def __pow__(a, b: complex, modulo: None = None) -> complex: ...
117+
else:
118+
@overload
119+
def __pow__(a, b: int) -> Fraction: ...
120+
@overload
121+
def __pow__(a, b: float | Fraction) -> float: ...
122+
@overload
123+
def __pow__(a, b: complex) -> complex: ...
124+
if sys.version_info >= (3, 14):
125+
@overload
126+
def __rpow__(b, a: float | Fraction, modulo: None = None) -> float: ...
127+
@overload
128+
def __rpow__(b, a: complex, modulo: None = None) -> complex: ...
129+
else:
130+
@overload
131+
def __rpow__(b, a: float | Fraction) -> float: ...
132+
@overload
133+
def __rpow__(b, a: complex) -> complex: ...
134+
120135
def __pos__(a) -> Fraction: ...
121136
def __neg__(a) -> Fraction: ...
122137
def __abs__(a) -> Fraction: ...

0 commit comments

Comments
 (0)