pytype is a static type analyzer that checks and infers types for Python code without executing it, catching errors at “compile time” and generating actionable diagnostics. It grew alongside Python typing at Google and can understand both inline annotations and unannotated code via powerful inference. The tool consumes stub files (.pyi) for the standard library and third-party packages (from typeshed and its own built-ins), enabling accurate checks even in large, mixed-quality codebases. Developers can run pytype locally or wire it into CI to prevent regressions and track tightening type discipline over time. Because pytype infers types, it’s useful during gradual typing, surfacing mismatches, missing attributes, or unsafe unions before runtime. Documentation and a user guide detail configuration, supported features, and how inference interacts with modern Python idioms.
Features
- Static analysis and type inference without executing code
- Scales to large codebases with mixed annotation quality
- Detection of attribute errors, bad unions, and incompatible calls
- CI-friendly error reporting and configuration knobs
- Integration with typeshed and project-specific stubs
- Support for inline annotations and gradual typing