I'd like a builtin type that doesn't require the numpy
dependency, but will allow me to express the fact that a variable is a real number. That is, an integer, a float, builtin or any of the fancy numpy
ones (numpy.int16
, numpy.float32
, etc.).
Now, numbers.Real
is almost right since instance and subclass checks work:
from numbers import Real
assert isinstance(10.0, Real)
assert issubclass(type(10.0), Real)
assert isinstance(np.int16(4), Real)
assert not isinstance(2 + 3j, Real)
Yet the following code:
import random
import numbers
def foo(x: numbers.Real, y: numbers.Real):
return random.uniform(x, y)
makes the linter complain that Expected type 'float', got 'Real' instead
.