pytype

Google’s 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 pytype using lintquarto

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

Running pytype...

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

ninja: Entering directory `.pytype'

[1/1] check typecheck_example

FAILED: [code=1] /home/runner/work/lintquarto/lintquarto/docs/pages/tools/.pytype/pyi/typecheck_example.qmdi 

/opt/hostedtoolcache/Python/3.12.11/x64/bin/python -m pytype.main --imports_info /home/runner/work/lintquarto/lintquarto/docs/pages/tools/.pytype/imports/typecheck_example.imports --module-name typecheck_example --platform linux -V 3.12 -o /home/runner/work/lintquarto/lintquarto/docs/pages/tools/.pytype/pyi/typecheck_example.qmdi --analyze-annotated --nofail --quick /home/runner/work/lintquarto/lintquarto/docs/pages/tools/examples/typecheck_example.qmd

/home/runner/work/lintquarto/lintquarto/docs/pages/tools/examples/typecheck_example.qmd:11:1: error: in <module>: Function add_numbers was called with the wrong arguments [wrong-arg-types]

         Expected: (a, b: int)

  Actually passed: (a, b: str)



add_numbers(3, "5")

~~~~~~~~~~~~~~~~~~~



/home/runner/work/lintquarto/lintquarto/docs/pages/tools/examples/typecheck_example.qmd:19:1: error: in <module>: Function add_numbers was called with the wrong arguments [wrong-arg-types]

         Expected: (a: int, ...)

  Actually passed: (a: str, ...)



add_numbers("apples", 8)

~~~~~~~~~~~~~~~~~~~~~~~~





For more details, see https://google.github.io/pytype/errors.html#wrong-arg-types

ninja: build stopped: subcommand failed.

Computing dependencies

Analyzing 1 sources with 0 local dependencies

Leaving directory '.pytype'