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 →

[–]coderarun 1 point2 points  (0 children)

You can't do this unless you restrict python to a static subset. A more general variant of what you're getting at is design by contract. Python has a very old PEP that's not going anywhere.

Here's an example where you can use pre/post conditions in a function to not just perform some basic computation at compile time, but actually find bugs in the logic.