Replies: 1 comment 2 replies
-
Zac: I thought about a response to this for quite a while and then completely forgot about it. Apologies. So, first: this idea is clever and seems at least moderately valuable. Sadly, branching on Just to confirm, for the first version, were you imagining that we'd check that we don't violate any contracts (or as usual, raise unexpected exceptions) under A much more minor stumbling block is that we don't have a pattern for describing the counterexample. CrossHair has evolved some patterns for counterexamples-under-context-managers, e.g. |
Beta Was this translation helpful? Give feedback.
-
If run with
python -O ...
, Python will strip out anyassert
statements and code dependent on the__debug__
constant at compile time. This occasionally causes bugs when users wrongly assume that such code will always be executed; some linters even recommend avoidingassert
which is IMO an overreaction.On one hand it's also pretty easy to check for: just run your code with
-O
and-OO
in addition to normal mode; on the other almost nobody actually does this... and on the gripping hand maybe it would be easy forcrosshair
to add an implicit branch on this? It's at most a 3x penalty, and I'd expect usually a lot less as most code doesn't depend on that value.Taking the idea further, people also claim that for this reason
assert
statements should be side-effect-free, which IMO is too strict a constraint: we only need them to be morally pure, i.e. not have invariant-violating side effects (whereas e.g. populating a cache is fine). I think a tool to disable a random subset of assertions should probably be a separate thing though, and can then be integrated into crosshair and/or a pytest plugin.Beta Was this translation helpful? Give feedback.
All reactions