Skip to content

Commit eec07e0

Browse files
committed
builtins: have the number types derive from the numbers ABCs
This makes e.g. this work: from decimal import Decimal from numbers import Real x: Real = 1.2 x = Decimal('1.2')
1 parent 919609d commit eec07e0

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

stdlib/2/__builtin__.pyi

+4-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ from typing import (
1111
)
1212
from abc import abstractmethod, ABCMeta
1313
from ast import mod, AST
14+
from numbers import Complex, Integral, Real
1415
from types import TracebackType, CodeType
1516
import sys
1617

@@ -127,7 +128,7 @@ class super(object):
127128
@overload
128129
def __init__(self, t: Any) -> None: ...
129130

130-
class int:
131+
class int(Integral):
131132
@overload
132133
def __init__(self, x: Union[Text, bytes, SupportsInt] = ...) -> None: ...
133134
@overload
@@ -208,7 +209,7 @@ class int:
208209
def __nonzero__(self) -> bool: ...
209210
def __index__(self) -> int: ...
210211

211-
class float:
212+
class float(Real):
212213
def __init__(self, x: Union[SupportsFloat, Text, bytes, bytearray] = ...) -> None: ...
213214
def as_integer_ratio(self) -> Tuple[int, int]: ...
214215
def hex(self) -> str: ...
@@ -271,7 +272,7 @@ class float:
271272
else:
272273
def __nonzero__(self) -> bool: ...
273274

274-
class complex:
275+
class complex(Complex):
275276
@overload
276277
def __init__(self, re: float = ..., im: float = ...) -> None: ...
277278
@overload

stdlib/2and3/builtins.pyi

+4-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ from typing import (
1111
)
1212
from abc import abstractmethod, ABCMeta
1313
from ast import mod, AST
14+
from numbers import Complex, Integral, Real
1415
from types import TracebackType, CodeType
1516
import sys
1617

@@ -127,7 +128,7 @@ class super(object):
127128
@overload
128129
def __init__(self, t: Any) -> None: ...
129130

130-
class int:
131+
class int(Integral):
131132
@overload
132133
def __init__(self, x: Union[Text, bytes, SupportsInt] = ...) -> None: ...
133134
@overload
@@ -208,7 +209,7 @@ class int:
208209
def __nonzero__(self) -> bool: ...
209210
def __index__(self) -> int: ...
210211

211-
class float:
212+
class float(Real):
212213
def __init__(self, x: Union[SupportsFloat, Text, bytes, bytearray] = ...) -> None: ...
213214
def as_integer_ratio(self) -> Tuple[int, int]: ...
214215
def hex(self) -> str: ...
@@ -271,7 +272,7 @@ class float:
271272
else:
272273
def __nonzero__(self) -> bool: ...
273274

274-
class complex:
275+
class complex(Complex):
275276
@overload
276277
def __init__(self, re: float = ..., im: float = ...) -> None: ...
277278
@overload

0 commit comments

Comments
 (0)