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

contracts on class structure #59

Open
asmodehn opened this issue Mar 16, 2017 · 1 comment
Open

contracts on class structure #59

asmodehn opened this issue Mar 16, 2017 · 1 comment

Comments

@asmodehn
Copy link

It would be helpful to check custom types.

For example if an instance of a class is defined as such :

class CustomClass(object):
    class_member = 42
    def __init__(self):
        inst_member = 23

cc_inst = CustomClass()

It would be useful to have a contract for a function that require such an instance.
To keep python duck-typing semantic, we can check the instance members (just like we do for dict), but checking one by one :

@contract("object(class_member: int, inst_member: int)")
def process_custom(custom_class_instance):
    [...]

This way any object that has an int class_member and an int inst_member will satisfy the contract.

I am posting this issue because I haven't found any way to do this currently...

@AndreaCensi
Copy link
Owner

AndreaCensi commented Sep 24, 2017

[deleted]

Sorry, I misunderstood what you meant. Yes, this would be a useful thing to have.

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

2 participants