From b390b3cb8e165550b349ba4cb24f474ad29a9d43 Mon Sep 17 00:00:00 2001
From: Alex Waygood
Date: Fri, 30 May 2025 22:45:28 +0100
Subject: [PATCH] [ty] Update docs for Python version inference (#18397)
---
crates/ty/docs/cli.md | 3 +--
crates/ty/src/args.rs | 8 ++++----
2 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/crates/ty/docs/cli.md b/crates/ty/docs/cli.md
index c98543117e..ae4382bd5d 100644
--- a/crates/ty/docs/cli.md
+++ b/crates/ty/docs/cli.md
@@ -72,8 +72,7 @@ over all configuration files.
This is used to specialize the type of sys.platform and will affect the visibility of platform-specific functions and attributes. If the value is set to all, no assumptions are made about the target platform. If unspecified, the current system's platform will be used.
--python-version, --target-version versionPython version to assume when resolving types.
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 Python version is inferred as the lower bound of the project's requires-python field from the pyproject.toml, if available. Otherwise, the latest stable version supported by ty is used, which is currently 3.13.
-ty will not infer the Python version from the Python environment at this time.
+By default, the Python version is inferred as the lower bound of the project's requires-python field from the pyproject.toml, if available. Otherwise, if a virtual environment has been configured or detected and a Python version can be inferred from the virtual environment's metadata, that version will be used. If neither of these applies, ty will fall back to the latest stable Python version supported by ty (currently 3.13).
Possible values:
3.7
diff --git a/crates/ty/src/args.rs b/crates/ty/src/args.rs
index d7f49f79f8..d2cfadcff9 100644
--- a/crates/ty/src/args.rs
+++ b/crates/ty/src/args.rs
@@ -82,10 +82,10 @@ pub(crate) struct CheckCommand {
/// type definitions of first- and third-party modules that are conditional on the Python version.
///
/// By default, the Python version is inferred as the lower bound of the project's
- /// `requires-python` field from the `pyproject.toml`, if available. Otherwise, the latest
- /// stable version supported by ty is used, which is currently 3.13.
- ///
- /// ty will not infer the Python version from the Python environment at this time.
+ /// `requires-python` field from the `pyproject.toml`, if available. Otherwise, if a virtual
+ /// environment has been configured or detected and a Python version can be inferred from the
+ /// virtual environment's metadata, that version will be used. If neither of these applies, ty
+ /// will fall back to the latest stable Python version supported by ty (currently 3.13).
#[arg(long, value_name = "VERSION", alias = "target-version")]
pub(crate) python_version: Option,