checks.typing.TypingCheck

checks.typing.TypingCheck()

Run type checking tools on the package.

Executes a static type checker to verify type annotations. Supports mypy and pyright, and by default runs the one the project has configured. A project that has configured neither is skipped.

Attributes

name :

The check identifier (“typing”).

description :

Human-readable description of this check.

rules :

The codes of the findings this check can report.

hints :

What to do about each code.

SUPPORTED_TOOLS :

List of supported type checking tools.

Configuration Options

tool (str): Type checker to use (“auto”, “mypy” or “pyright”). Defaults to “auto”, the type checker the project has configured. strict (bool): Whether to pass --strict to mypy. Defaults to False. pyright reads strict mode from its own configuration. args (list[str]): Additional arguments to pass to the type checker. timeout (float): Seconds the type checker may run. Defaults to 300.

Examples

Run the type checker the project has configured:

>>> from pathlib import Path
>>> check = TypingCheck()
>>> result = check.run(Path("."), {"enabled": True})
>>> result.name
'typing'

Run pyright, whatever the project has configured:

>>> config = {"enabled": True, "tool": "pyright"}
>>> result = check.run(Path("."), config)

Run mypy in strict mode:

>>> config = {"enabled": True, "tool": "mypy", "strict": True}
>>> result = check.run(Path("."), config)

Methods

Name Description
run Run type checking on the package.

run

checks.typing.TypingCheck.run(package_path, config)

Run type checking on the package.

Executes the type checker and collects any errors found. With tool = "auto" that is the type checker the project has configured, and a project that has configured none is skipped. Errors are reported in the result details (the first MAX_DETAIL_LINES of them). A pyright run that ends with exit code 1 lists its warnings there too, and the message counts them apart. When the check can read no line of the output, the details hold the end of it.

Parameters

package_path : Path

Path to the package directory to check.

config : dict[str, Any]

Configuration dictionary with options: - tool (str): “auto”, “mypy” or “pyright” (default: “auto”) - strict (bool): Pass –strict to mypy (default: False) - args (list[str]): Additional arguments for the checker - timeout (float): Time limit in seconds (default: 300)

Returns

: CheckResult

A CheckResult with:

: CheckResult
  • OK status if no type errors found
: CheckResult
  • WARNING status if the type checker is installed but could not run
: CheckResult
  • ERROR status if type errors found, the type checker times out, or an unsupported tool or an invalid option is specified
: CheckResult
  • SKIPPED status if the project has configured no type checker, the type checker is not installed, or pyproject.toml could not be read and no other file configures a type checker, which the metadata check reports (“prerequisite-failed”)