mypy

Python’s popular static type checker.

PyPI View on PyPI GitHub View on GitHub Conda View on Conda

Example Quarto .qmd file:

1:     ---
2:     title: "Example"
3:     ---
4:     
5:     This file contains some issues for the linter (static type checker) to identify.
6:     
7:     ```{python}
8:     def add_numbers(a: int, b: int) -> int:
9:         return a + b
10:    
11:    add_numbers(3, "5")
12:    ```
13:    
14:    There's some more issues below...
15:    
16:    ```{python}
17:    add_numbers(1, 4)
18:    
19:    add_numbers("apples", 8)
20:    ```

Run mypy using lintquarto

lintquarto -l mypy -p typecheck_example.qmd
=============================================================

Running mypy...

=============================================================

examples/typecheck_example.py:11: error: Argument 2 to "add_numbers" has incompatible type "str"; expected "int"  [arg-type]

examples/typecheck_example.py:19: error: Argument 1 to "add_numbers" has incompatible type "str"; expected "int"  [arg-type]

Found 2 errors in 1 file (checked 1 source file)