Comments (7)
I am warming up to this request generally. And, FWIW, I think some sort of hypothesis cooperation also makes a lot of sense.
In the assert version, do you imagine pulling the AST, and making the assumption that the first non-assert statement in the body signals the transition from preconditions to postconditions?
from crosshair.
@Zac-HD This is in-progress :)
In other modes, CrossHair detects other kinds of exceptions too. I'm thinking this is useful under "assert mode" as well.
One notable exception might be ValueError & TypeError which are likely validating inputs? Or perhaps any exception raised directly in the body of the function under analysis? WDYT?
from crosshair.
A basic version of this is in HEAD! (minimalistic docs)
At least one leading assert is required, and it'll complain about any kind of exception.
There are no flags/options to control the behavior yet; I think I'm inclined to wait for feedback from real use cases? Another option for exception handling would be to borrow just the raises: <exception type>
pattern from the docstring parser for suppressing exception reports.
from crosshair.
Docstring directives like "raises: IndexError" should work.
Complete docs for assert mode are here now.
Closing this FR!
from crosshair.
An alternative would be to special-case a function called assume
, which might be implemented as
def assume(predicate):
assert predicate
and treat assume(x)
as expressing a precondition of bool(x) is True
rather than an assertion. This would also play nicely with the hypothesis.assume()
function, which does exactly this (albeit implemented with a special exception type). Other projects could add domain-specific logic such as logging that the precondition was violated or attempting to recover to a known-good state.
from crosshair.
In the assert version, do you imagine pulling the AST, and making the assumption that the first non-assert statement in the body signals the transition from preconditions to postconditions?
Exactly, though it should probably be configurable at the project level and also have some local way to force all-assertions-are-invariants.
from crosshair.
One notable exception might be ValueError & TypeError which are likely validating inputs? Or perhaps any exception raised directly in the body of the function under analysis? WDYT?
Maybe as a separate flag - I think this is probably useful, but also prone to concealing real bugs in a way that assertions-only is not.
from crosshair.
Related Issues (20)
- Unexpected counterexample when indexing a symbolic sequence by a object of unknown type
- Support annotated-types HOT 1
- Better error message when a file can't be imported HOT 1
- Check __return__ is not None
- Do not treat KeyboardInterrupt as an exception in code-under-analysis
- Some easy cases cannot be solved HOT 6
- Support atomic grouping and possessive quantifiers
- Support correct and compilable representation of enum values in the cover/pytest mode HOT 7
- Support pytest.raises Assertion / Exception match parameter when there is a message in exception HOT 1
- Produce the correct import statements for pytest output on cover command HOT 1
- CrossHair is missing symbolic support for `str.split` without arguments
- Support Python 3.12 HOT 1
- Implement true floating point semantics
- Unexpected checking results for functions with/without type annotations HOT 4
- Generic objects, when realized to strings, raise TypeError on concatenation.
- CrosshairInternal error raised when attempting to use symbolic integer as a function HOT 1
- Ensure all isinstance checks account for undecided types
- cover command error: (AttributeError("'AlgebraicNumRef' object has no attribute 'as_fraction'") HOT 2
- Unexpectedly long run times on a short example containing floats HOT 2
- Improve premature realization heuristics
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from crosshair.