PyContracts is a Python package that allows to declare constraints on function parameters and return values. Contracts can be specified using Python3 annotations, or inside a docstring. PyContracts supports a basic type system, variables binding, arithmetic constraints, and has several specialized contracts and an extension API.
I noticed that in the current master (6454b66052), import contracts fails when numpy is not installed:
$ git clone git://github.com/AndreaCensi/contracts.git
...
$ virtualenv venv
...
$ venv/bin/python --version
Python 2.7.5
$ venv/bin/pip install ./contracts
...
$ venv/bin/python -c 'import contracts'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Users/ryan.heimbuch/src/venv/lib/python2.7/site-packages/contracts/__init__.py", line 43, in <module>
from .useful_contracts import *
File "/Users/ryan.heimbuch/src/venv/lib/python2.7/site-packages/contracts/useful_contracts/__init__.py", line 1, in <module>
from .numpy_specific import *
File "/Users/ryan.heimbuch/src/venv/lib/python2.7/site-packages/contracts/useful_contracts/numpy_specific.py", line 2, in <module>
import numpy as np
ImportError: No module named numpy
I found a conditional import check that used to be present in src/contracts/useful_contracts/__init__.py but was removed in commit cfe9bb78d. I feel like this was probably an oversight during the refactoring of the contracts.useful_contracts package. I've added back a try/except/else block around the from .numpy_specific import * statement.
I noticed that in the current master (6454b66052),
import contracts
fails when numpy is not installed:I found a conditional import check that used to be present in
src/contracts/useful_contracts/__init__.py
but was removed in commit cfe9bb78d. I feel like this was probably an oversight during the refactoring of thecontracts.useful_contracts
package. I've added back a try/except/else block around thefrom .numpy_specific import *
statement.