CrossHair analyzes Python code with symbolic execution and SMT solving to find contract violations and counterexamples. It links runtime checking with type-annotated functions.
Overview
CrossHair is an analysis tool for Python that sits between conventional testing and type-driven checking. Given functions with type annotations and contracts in a supported syntax, it explores execution paths with symbolic inputs and uses an SMT solver to hunt for counterexamples.
The tool can reason about built-in types, user-defined classes, and much of the standard library. Hypothesis can optionally use CrossHair as a backend for property-based testing. You can try it in a browser without installing locally, and extensions exist for VS Code, PyCharm, and other editors.
Beyond contract checking, CrossHair can generate unit tests and compare behavior between two implementations of a function. Documentation covers contracts, coverage-style analysis, behavioral diffs, class hints, IDE setup, limitations, and plugins.
Key features
- Symbolic execution with SMT solving
- Contract and type-annotation checking
- Counterexample search for Python code
- Unit test generation
- Behavioral difference detection
- Browser-based demo environment
- IDE plugins for major editors
- Optional Hypothesis backend integration
Use cases
- Validating Python contracts and annotations
- Finding edge-case bugs before production
- Generating tests from specifications
- Comparing two function implementations
- Property-based testing with symbolic backends