mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 21:34:57 +00:00
[ty] document how the default value for python-version
is determined (#18549)
Co-authored-by: detachhead <detachhead@users.noreply.github.com> Co-authored-by: Alex Waygood <alex.waygood@gmail.com>
This commit is contained in:
parent
07cb84426d
commit
ae2150bfa3
3 changed files with 25 additions and 7 deletions
15
crates/ty/docs/configuration.md
generated
15
crates/ty/docs/configuration.md
generated
|
@ -106,9 +106,18 @@ The version should be specified as a string in the format `M.m` where `M` is the
|
|||
and `m` is the minor (e.g. `"3.0"` or `"3.6"`).
|
||||
If a version is provided, ty will generate errors if the source code makes use of language features
|
||||
that are not supported in that version.
|
||||
It will also understand conditionals based on comparisons with `sys.version_info`, such
|
||||
as are commonly found in typeshed to reflect the differing contents of the standard
|
||||
library across Python versions.
|
||||
|
||||
If a version is not specified, ty will try the following techniques in order of preference
|
||||
to determine a value:
|
||||
1. Check for the `project.requires-python` setting in a `pyproject.toml` file
|
||||
and use the minimum version from the specified range
|
||||
2. Check for an activated or configured virtual environment
|
||||
and use the Python version of that environment
|
||||
3. Fall back to the default value (see below)
|
||||
|
||||
For some language features, ty can also understand conditionals based on comparisons
|
||||
with `sys.version_info`. These are commonly found in typeshed, for example,
|
||||
to reflect the differing contents of the standard library across Python versions.
|
||||
|
||||
**Default value**: `"3.13"`
|
||||
|
||||
|
|
|
@ -317,9 +317,18 @@ pub struct EnvironmentOptions {
|
|||
/// and `m` is the minor (e.g. `"3.0"` or `"3.6"`).
|
||||
/// If a version is provided, ty will generate errors if the source code makes use of language features
|
||||
/// that are not supported in that version.
|
||||
/// It will also understand conditionals based on comparisons with `sys.version_info`, such
|
||||
/// as are commonly found in typeshed to reflect the differing contents of the standard
|
||||
/// library across Python versions.
|
||||
///
|
||||
/// If a version is not specified, ty will try the following techniques in order of preference
|
||||
/// to determine a value:
|
||||
/// 1. Check for the `project.requires-python` setting in a `pyproject.toml` file
|
||||
/// and use the minimum version from the specified range
|
||||
/// 2. Check for an activated or configured virtual environment
|
||||
/// and use the Python version of that environment
|
||||
/// 3. Fall back to the default value (see below)
|
||||
///
|
||||
/// For some language features, ty can also understand conditionals based on comparisons
|
||||
/// with `sys.version_info`. These are commonly found in typeshed, for example,
|
||||
/// to reflect the differing contents of the standard library across Python versions.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[option(
|
||||
default = r#""3.13""#,
|
||||
|
|
2
ty.schema.json
generated
2
ty.schema.json
generated
|
@ -99,7 +99,7 @@
|
|||
]
|
||||
},
|
||||
"python-version": {
|
||||
"description": "Specifies the version of Python that will be used to analyze the source code. The version should be specified as a string in the format `M.m` where `M` is the major version and `m` is the minor (e.g. `\"3.0\"` or `\"3.6\"`). If a version is provided, ty will generate errors if the source code makes use of language features that are not supported in that version. It will also understand conditionals based on comparisons with `sys.version_info`, such as are commonly found in typeshed to reflect the differing contents of the standard library across Python versions.",
|
||||
"description": "Specifies the version of Python that will be used to analyze the source code. The version should be specified as a string in the format `M.m` where `M` is the major version and `m` is the minor (e.g. `\"3.0\"` or `\"3.6\"`). If a version is provided, ty will generate errors if the source code makes use of language features that are not supported in that version.\n\nIf a version is not specified, ty will try the following techniques in order of preference to determine a value: 1. Check for the `project.requires-python` setting in a `pyproject.toml` file and use the minimum version from the specified range 2. Check for an activated or configured virtual environment and use the Python version of that environment 3. Fall back to the default value (see below)\n\nFor some language features, ty can also understand conditionals based on comparisons with `sys.version_info`. These are commonly found in typeshed, for example, to reflect the differing contents of the standard library across Python versions.",
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/PythonVersion"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue