Show HN: A design-by-contract Python package in ~100 lines (github.com)
Greetings! A 2.5 weekends project to teach myself newer Python features (>= 3.10). Conditions are written as Lambda expressions that annotate parameters and return types, and coexist with type annotations. Symbols to share values between conditions are also supported to a limited extend.
12 comments
[ 3.5 ms ] story [ 44.1 ms ] threadI think normally this sort of thing is useful so you can statically check stuff. If it's runtime only that seems a bit useless.
Also, then you need annotation and tests to validate your annotations!
def foobar(a: '(i>1, j)', b: '(j, k)') -> '(k,)':
How does using this effect performance? [edit: strike that i see that in another comment you said you don't know]
I remember someone wrote one of these for ruby and the performance impacts of their implementation were just brutal. Like, 2x slower or something (it was a long time ago). Dunno if it was a bad implementation or just something about ruby.
But in fact the most crucial aspect of contracts for me is invariants.