Skip to content

Commit 2a115b1

Browse files
eddiejessupJelleZijlstra
authored andcommitted
Indicate that float() accepts Real objects (#1434)
This contradicts CPython, in `Lib/numbers.py`, because `Real` does not actually inherit from `SupportsFloat`. But it suppresses errors from mypy when passing sub-classes like `fractions.Fraction` to `float()`.
1 parent ee5e3af commit 2a115b1

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

stdlib/2and3/numbers.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Note: these stubs are incomplete. The more complex type
66
# signatures are currently omitted.
77

8-
from typing import Any, Optional, TypeVar
8+
from typing import Any, Optional, TypeVar, SupportsFloat
99
from abc import ABCMeta, abstractmethod
1010
import sys
1111

@@ -59,7 +59,7 @@ class Complex(Number):
5959
if sys.version_info < (3, 0):
6060
def __ne__(self, other: object) -> bool: ...
6161

62-
class Real(Complex):
62+
class Real(Complex, SupportsFloat):
6363
@abstractmethod
6464
def __float__(self) -> float: ...
6565
@abstractmethod

0 commit comments

Comments
 (0)