Add note about how Ruff handles PYI files wrt target version (#13111)

Co-authored-by: Alex Waygood <alex.waygood@gmail.com>
This commit is contained in:
Calum Young 2024-08-27 18:28:22 +01:00 committed by GitHub
parent aba1802828
commit eb3dc37faa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 1 deletions

View file

@ -308,6 +308,16 @@ pub struct Options {
///
/// If both are specified, `target-version` takes precedence over
/// `requires-python`.
///
/// Note that a stub file can [sometimes make use of a typing feature](https://typing.readthedocs.io/en/latest/spec/distributing.html#syntax)
/// before it is available at runtime, as long as the stub does not make
/// use of new *syntax*. For example, a type checker will understand
/// `int | str` in a stub as being a `Union` type annotation, even if the
/// type checker is run using Python 3.9, despite the fact that the `|`
/// operator can only be used to create union types at runtime on Python
/// 3.10+. As such, Ruff will often recommend newer features in a stub
/// file than it would for an equivalent runtime file with the same target
/// version.
#[option(
default = r#""py38""#,
value_type = r#""py37" | "py38" | "py39" | "py310" | "py311" | "py312""#,

2
ruff.schema.json generated
View file

@ -693,7 +693,7 @@
]
},
"target-version": {
"description": "The minimum Python version to target, e.g., when considering automatic code upgrades, like rewriting type annotations. Ruff will not propose changes using features that are not available in the given version.\n\nFor example, to represent supporting Python >=3.10 or ==3.10 specify `target-version = \"py310\"`.\n\nIf you're already using a `pyproject.toml` file, we recommend `project.requires-python` instead, as it's based on Python packaging standards, and will be respected by other tools. For example, Ruff treats the following as identical to `target-version = \"py38\"`:\n\n```toml [project] requires-python = \">=3.8\" ```\n\nIf both are specified, `target-version` takes precedence over `requires-python`.",
"description": "The minimum Python version to target, e.g., when considering automatic code upgrades, like rewriting type annotations. Ruff will not propose changes using features that are not available in the given version.\n\nFor example, to represent supporting Python >=3.10 or ==3.10 specify `target-version = \"py310\"`.\n\nIf you're already using a `pyproject.toml` file, we recommend `project.requires-python` instead, as it's based on Python packaging standards, and will be respected by other tools. For example, Ruff treats the following as identical to `target-version = \"py38\"`:\n\n```toml [project] requires-python = \">=3.8\" ```\n\nIf both are specified, `target-version` takes precedence over `requires-python`.\n\nNote that a stub file can [sometimes make use of a typing feature](https://typing.readthedocs.io/en/latest/spec/distributing.html#syntax) before it is available at runtime, as long as the stub does not make use of new *syntax*. For example, a type checker will understand `int | str` in a stub as being a `Union` type annotation, even if the type checker is run using Python 3.9, despite the fact that the `|` operator can only be used to create union types at runtime on Python 3.10+. As such, Ruff will often recommend newer features in a stub file than it would for an equivalent runtime file with the same target version.",
"anyOf": [
{
"$ref": "#/definitions/PythonVersion"