contracts
contracts copied to clipboard
Boolean values are allowed to be returned when int required.
This small example should be all that is needed to explain the problem.
from contracts import contract
@contract(url=str, returns=int)
def validate_url(url=""):
""" returns True if the input is a valid url """
return False
print validate_url("google.com")
# False
FYI booleans are integer in python :
Python 2.7.6 (default, Oct 26 2016, 20:30:19)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> isinstance(True, int)
True
>>> False == 0
True
>>> True == 1
True
So I dont think much can be done here...
Would it be crazy to say if booleans specifically are being specified this would be used for the test instead?
type(True) == bool
Its a little less flexible but being that design by contract is a little more strict than the general python, I feel like its appropriate.