Skip to content

doc: Add type checker configuration for ty, pyrefly and others - #752

Open
echoix wants to merge 3 commits into
mainfrom
typecheck-env
Open

echoix wants to merge 3 commits into
mainfrom
typecheck-env

Conversation

@echoix

@echoix echoix commented Oct 27, 2026

Copy link
Copy Markdown
Owner

Description

Adds [tool.ty] and [tool.pyrefly] sections to pyproject.toml (plus venvPath for pyright) without machine-specific paths, a "Type checking" section in doc/development/testing.md, and utils/typecheck_env.py.

The generated grass.lib package only exists in a build or install tree, so checkers must be pointed to one. Two approaches are documented:

  1. Run in a GRASS session (CLI, CI): grass --tmp-project XY --exec ty check. The launcher sets PYTHONPATH; no setup needed.
  2. Virtual environment (editors such as VS Code): python utils/typecheck_env.py creates .venv with a .pth file pointing to the build or install tree, which language servers pick up through the selected interpreter.

Motivation and context

A single static config that works for Autotools, CMake and installed trees on any platform.

ty needs root = ["."]: otherwise it finds python/grass first and does not look for grass.lib elsewhere.

How has this been tested?

CMake build on Linux. grass.lib resolved with no import errors by ty, pyrefly, Zuban, pyright and basedpyright, in both approaches (the .venv route was checked with ty only). Full python/ run through grass --exec:

Checker Time Diagnostics
Zuban 1.5 s 4,582
ty 3.2 s 1,531
pyrefly 3.3 s 4,574
basedpyright 308 s 5,008 errors
pyright 350 s 4,661

Not tested: Autotools or installed trees, Windows, VS Code itself.

Known limitations: results are not clean (mostly the runtime _ gettext builtin and missing optional dependencies), so nothing is enforced. The grass package comes from the build copy, so source edits need a rebuild to show up in cross-module checks.

Written with AI assistance (Claude); the script and config are small and every line was reviewed.

Types of changes

  • New feature (non-breaking change which adds functionality)

Checklist

  • PR title provides summary of the changes and starts with one of the
    pre-defined prefixes
  • My code follows the code style
    of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.

Generated by Claude Code

…ment script

Add [tool.ty] and [tool.pyrefly] sections without machine-specific paths.
The new utils/typecheck_env.py creates a virtual environment whose .pth file
points to the Python code of a GRASS build or installation, so that type
checkers find the generated grass.lib package. Pyright is pointed to the
same environment.

The configuration and script were written with AI assistance.
…tual environment

The grass launcher sets PYTHONPATH to the Python code of the build or
installation, which ty, pyrefly, pyright, basedpyright and Zuban all use to
find the generated grass.lib package. This removes the need for a helper
script and for any machine-specific path in the configuration.
…ronment script for editors

Describe two ways to let type checkers find the generated grass.lib package:
running them in a GRASS session, and a virtual environment created by
utils/typecheck_env.py for editors. The configuration and script were written
with AI assistance.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants