Giter Club home page Giter Club logo

Comments (7)

pschanely avatar pschanely commented on June 8, 2024 1

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.

pschanely avatar pschanely commented on June 8, 2024 1

@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.

pschanely avatar pschanely commented on June 8, 2024 1

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.

pschanely avatar pschanely commented on June 8, 2024 1

Docstring directives like "raises: IndexError" should work.
Complete docs for assert mode are here now.
Closing this FR!

from crosshair.

Zac-HD avatar Zac-HD commented on June 8, 2024

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.

Zac-HD avatar Zac-HD commented on June 8, 2024

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.

Zac-HD avatar Zac-HD commented on June 8, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.