|
3 | 3 | from typing import Any, NoReturn
|
4 | 4 | from typing_extensions import Literal, assert_type
|
5 | 5 |
|
6 |
| -assert_type(pow(1, 0), Literal[1]) # See #7163 |
7 |
| -assert_type(pow(1, 0, None), Literal[1]) # See #7163 |
| 6 | +# See #7163 |
| 7 | +assert_type(pow(1, 0), Literal[1]) |
| 8 | +assert_type(1**0, Literal[1]) |
| 9 | +assert_type(pow(1, 0, None), Literal[1]) |
| 10 | + |
8 | 11 | assert_type(pow(2, 4, 0), NoReturn)
|
| 12 | + |
9 | 13 | assert_type(pow(2, 4), int)
|
| 14 | +assert_type(2**4, int) |
10 | 15 | assert_type(pow(4, 6, None), int)
|
| 16 | + |
11 | 17 | assert_type(pow(5, -7), float)
|
| 18 | +assert_type(5**-7, float) |
| 19 | + |
12 | 20 | assert_type(pow(2, 4, 5), int) # pow(<smallint>, <smallint>, <smallint>)
|
13 | 21 | assert_type(pow(2, 35, 3), int) # pow(<smallint>, <bigint>, <smallint>)
|
| 22 | + |
| 23 | +assert_type(pow(2, 8.5), float) |
| 24 | +assert_type(2**8.6, float) |
| 25 | +assert_type(pow(2, 8.6, None), float) |
| 26 | + |
| 27 | +# TODO: Why does this pass pyright but not mypy?? |
| 28 | +# assert_type((-2) ** 0.5, complex) |
| 29 | + |
| 30 | +assert_type(pow((-5), 8.42, None), complex) |
| 31 | + |
14 | 32 | assert_type(pow(4.6, 8), float)
|
| 33 | +assert_type(4.6**8, float) |
15 | 34 | assert_type(pow(5.1, 4, None), float)
|
| 35 | + |
16 | 36 | assert_type(pow(complex(6), 6.2), complex)
|
| 37 | +assert_type(complex(6) ** 6.2, complex) |
17 | 38 | assert_type(pow(complex(9), 7.3, None), complex)
|
| 39 | + |
18 | 40 | assert_type(pow(Fraction(), 4, None), Fraction)
|
| 41 | +assert_type(Fraction() ** 4, Fraction) |
| 42 | + |
19 | 43 | assert_type(pow(Fraction(3, 7), complex(1, 8)), complex)
|
| 44 | +assert_type(Fraction(3, 7) ** complex(1, 8), complex) |
| 45 | + |
20 | 46 | assert_type(pow(complex(4, -8), Fraction(2, 3)), complex)
|
| 47 | +assert_type(complex(4, -8) ** Fraction(2, 3), complex) |
| 48 | + |
21 | 49 | assert_type(pow(Decimal("1.0"), Decimal("1.6")), Decimal)
|
| 50 | +assert_type(Decimal("1.0") ** Decimal("1.6"), Decimal) |
| 51 | + |
22 | 52 | assert_type(pow(Decimal("1.0"), Decimal("1.0"), Decimal("1.0")), Decimal)
|
23 | 53 | assert_type(pow(Decimal("4.6"), 7, None), Decimal)
|
| 54 | +assert_type(Decimal("4.6") ** 7, Decimal) |
24 | 55 |
|
25 | 56 | # These would ideally be more precise, but `Any` is acceptable
|
26 | 57 | # They have to be `Any` due to the fact that type-checkers can't distinguish between positive and negative numbers for the second argument to `pow()`
|
|
29 | 60 | assert_type(pow(4, 65), Any)
|
30 | 61 | assert_type(pow(2, -45), Any)
|
31 | 62 | assert_type(pow(3, 57, None), Any)
|
| 63 | +assert_type(pow(67, 0.98, None), Any) |
| 64 | +assert_type(87**7.32, Any) |
32 | 65 | # pow(<pos-float>, <pos-or-neg-float>) -> float
|
33 | 66 | # pow(<neg-float>, <pos-or-neg-float>) -> complex
|
34 | 67 | assert_type(pow(4.7, 7.4), Any)
|
|
37 | 70 | assert_type(pow(8.2, -9.8), Any)
|
38 | 71 | assert_type(pow(4.7, 9.2, None), Any)
|
39 | 72 | # See #7046 -- float for a positive 1st arg, complex otherwise
|
40 |
| -assert_type((-2) ** 0.5, Any) |
| 73 | +assert_type((-95) ** 8.42, Any) |
0 commit comments