arogozhnikov / python3_with_pleasure

A short guide on features of Python 3 with examples
3.63k stars 242 forks source link

int is not a substitute for numbers.Integral #34

Closed eric-wieser closed 5 years ago

eric-wieser commented 5 years ago

This section recommends:

isinstance(x, numbers.Integral) # Python 2, the canonical way
isinstance(x, (long, int))      # Python 2
isinstance(x, int)              # Python 3, easier to remember

The first of these will work on types like np.int16, whereas your proposed python 3 substitution does not.

arogozhnikov commented 5 years ago

Hi @eric-wieser, thanks for noting, I definitely didn't think about that (again special case for scalars ... )