AndreaCensi/contracts — Issue #3: Can the number contract allow numpy.number?
Author: wickedgrey
Created: 2011-11-04 03:35:39+00:00
State: open

Currently, the 'number' contract does not allow instances of numpy.float32 (or numpy.number in general), which surprised me. I think it would be nice to either:

- Change 'number' to include numpy.number
- Add a new default contract that is similar to 'number' with a different name that includes numpy.number
- Update the documentation to explicitly mention that numpy numbers aren't allowed with 'number'

I think that it would be a change to https://github.com/AndreaCensi/contracts/blob/master/src/contracts/library/types_misc.py#L48 :

```python
try:
import numpy
number_types = (Number, numpy.number)
except ImportError:
number_types = Number

add_contract(Keyword('number').setParseAction(CheckType.parse_action(number_types)))
```

For reference, here is the MRO for numpy.float32:

>>> inspect.getmro(numpy.float32)
(, , , , , )

Thanks!