|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
| 3 | +import sys |
3 | 4 | from decimal import Decimal |
4 | 5 | from fractions import Fraction |
5 | 6 | from typing import Any, Literal |
|
47 | 48 | assert_type(complex(6) ** 6.2, complex) |
48 | 49 | assert_type(pow(complex(9), 7.3, None), complex) |
49 | 50 |
|
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] |
53 | 51 | assert_type(Fraction() ** 4, Fraction) |
54 | 52 |
|
55 | 53 | assert_type(pow(Fraction(3, 7), complex(1, 8)), complex) |
|
85 | 83 | # See #7046 -- float for a positive 1st arg, complex otherwise |
86 | 84 | assert_type((-95) ** 8.42, Any) |
87 | 85 |
|
| 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 | + |
88 | 97 | # All of the following cases should fail a type-checker. |
89 | 98 | pow(1.9, 4, 6) # type: ignore |
90 | 99 | pow(4, 7, 4.32) # type: ignore |
91 | 100 | pow(6.2, 5.9, 73) # type: ignore |
92 | 101 | pow(complex(6), 6.2, 7) # type: ignore |
93 | | -pow(Fraction(), 5, 8) # type: ignore |
94 | 102 | Decimal("8.7") ** 3.14 # type: ignore |
95 | 103 |
|
96 | 104 | # TODO: This fails at runtime, but currently passes mypy and pyright: |
|
0 commit comments