basedpyright icon indicating copy to clipboard operation
basedpyright copied to clipboard

Feature Request: Automatically Use `project.requires-python` as `pythonVersion` in Basedpyright Configuration

Open A-kirami opened this issue 1 year ago • 3 comments

This feature request proposes that Basedpyright should automatically use the requires-python field from the [project] section of pyproject.toml as the default value for the pythonVersion setting in the [tool.basedpyright] section. This would ensure consistency between the project's required Python version and the version used by Basedpyright for static analysis.

Related Issue: https://github.com/microsoft/pyright/issues/7561

A-kirami avatar Dec 02 '24 10:12 A-kirami

i like this idea. though i think to do this we would also need to do #8, since requires-python can be a range, eg:

[project]
requires-python = ">=3.9,<3.14"

DetachHead avatar Dec 02 '24 11:12 DetachHead

I also like this. Ruff uses this too. I think for now you can set it to the minimum version because that's usually what you want to target.

kiyoon avatar Dec 20 '24 05:12 kiyoon

Astral's ty typechecker has this to say about how it uses [project].requires-python:

The Python version affects allowed syntax, type definitions of the standard library, and type definitions of first- and third-party modules that are conditional on the Python version.

By default, the lower bound of the project's requires-python field (from the pyproject.toml) is used as the target Python version, ensuring that features and symbols only available in newer Python versions are not used.

frou avatar Oct 23 '25 11:10 frou