Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support checking both type annotations and docstring contracts #79

Open
AaronCritchley opened this issue Feb 5, 2019 · 0 comments
Open

Comments

@AaronCritchley
Copy link

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. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant