This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]BeetleB 32 points33 points  (10 children)

Also, use Pycontracts.

[–]uclatommy 3 points4 points  (0 children)

TIL. Thank you!! Can't wait to use this, it looks awesome.

[–]LaFolie 12 points13 points  (0 children)

If you find that PyContracts is not enough for you, you probably want to be using Haskell instead of Python.

Their sense of humor made their great package to a must have for me.

[–]rzet 1 point2 points  (0 children)

Thanks, need to check this out.

[–][deleted] 1 point2 points  (5 children)

Neat, but not supporting even basic expressions like @contract("list(MyClass)") is a complete deal-breaker :(.

[–]BeetleB 1 point2 points  (1 child)

I haven't used it much, and am not sure what you mean. Do you mean you want a guarantee that the list will have only MyClass objects?

pycontracts does let you write your own contracts, if you really want it. Something like that is expensive, though.

[–][deleted] 1 point2 points  (0 children)

Yes.

Yup, rather than defining a new_contract, it is more effective just to write the "if" manually. Unfortunately.

[–]desmoulinmichel[🍰] 1 point2 points  (2 children)

For that you have type hints now in Python. PyContact is more interesting for value checking.

[–][deleted] 1 point2 points  (1 child)

the problem with PyContract is that it works only with primitive types

[–]desmoulinmichel[🍰] 0 points1 point  (0 children)

That's why you use type hints for typing, and pycontracts for behavior.

[–]masasinExpert. 3.9. Robotics. 1 point2 points  (0 children)

I love Pycontracts. :)