Support checking both type annotations and docstring contracts
Opened this issue · 0 comments
AaronCritchley commented
Hey,
When using contracts, we often would like to provide type hints to help the IDE, whilst having more complex contracts in the docstring to be checked. Can I add support for this to PyContracts? I'm happy if it falls behind a configuration flag or something similar.
An over simplified example could be:
@contract
def add_gt_5(x: int, y: int):
"""
Add two numbers that are both greater than 5
:type x: int, >5
:type y: int, >5
:rtype: int, >11
"""
return x + y
add_gt_5(10, 10) # Fine
add_gt_5(2, 2) # Should fail
I'm aware we can specify contracts as strings in the type annotations but then the IDE cannot decipher types to make life easier for the user.
Again, I'm happy to make this change just want to check that you're happy with it being in master. 😄