From e338d2095e1f191bec41fa9234511357ed5d17fa Mon Sep 17 00:00:00 2001 From: Matt Norton Date: Tue, 14 Oct 2025 07:43:24 +0100 Subject: [PATCH] Update `lint.flake8-type-checking.quoted-annotations` docs (#20765) Co-authored-by: Micha Reiser --- crates/ruff_workspace/src/options.rs | 3 ++- ruff.schema.json | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/ruff_workspace/src/options.rs b/crates/ruff_workspace/src/options.rs index 21fc2269eb..0260b5f9e5 100644 --- a/crates/ruff_workspace/src/options.rs +++ b/crates/ruff_workspace/src/options.rs @@ -2168,7 +2168,8 @@ pub struct Flake8TypeCheckingOptions { /// /// Note that this setting has no effect when `from __future__ import annotations` /// is present, as `__future__` annotations are always treated equivalently - /// to quoted annotations. + /// to quoted annotations. Similarly, this setting has no effect on Python + /// versions after 3.14 because these annotations are also deferred. #[option( default = "false", value_type = "bool", diff --git a/ruff.schema.json b/ruff.schema.json index 684d9e56ee..33ccab9364 100644 --- a/ruff.schema.json +++ b/ruff.schema.json @@ -1474,7 +1474,7 @@ } }, "quote-annotations": { - "description": "Whether to add quotes around type annotations, if doing so would allow the corresponding import to be moved into a type-checking block.\n\nFor example, in the following, Python requires that `Sequence` be available at runtime, despite the fact that it's only used in a type annotation:\n\n```python from collections.abc import Sequence\n\ndef func(value: Sequence[int]) -> None: ... ```\n\nIn other words, moving `from collections.abc import Sequence` into an `if TYPE_CHECKING:` block above would cause a runtime error, as the type would no longer be available at runtime.\n\nBy default, Ruff will respect such runtime semantics and avoid moving the import to prevent such runtime errors.\n\nSetting `quote-annotations` to `true` will instruct Ruff to add quotes around the annotation (e.g., `\"Sequence[int]\"`), which in turn enables Ruff to move the import into an `if TYPE_CHECKING:` block, like so:\n\n```python from typing import TYPE_CHECKING\n\nif TYPE_CHECKING: from collections.abc import Sequence\n\ndef func(value: \"Sequence[int]\") -> None: ... ```\n\nNote that this setting has no effect when `from __future__ import annotations` is present, as `__future__` annotations are always treated equivalently to quoted annotations.", + "description": "Whether to add quotes around type annotations, if doing so would allow the corresponding import to be moved into a type-checking block.\n\nFor example, in the following, Python requires that `Sequence` be available at runtime, despite the fact that it's only used in a type annotation:\n\n```python from collections.abc import Sequence\n\ndef func(value: Sequence[int]) -> None: ... ```\n\nIn other words, moving `from collections.abc import Sequence` into an `if TYPE_CHECKING:` block above would cause a runtime error, as the type would no longer be available at runtime.\n\nBy default, Ruff will respect such runtime semantics and avoid moving the import to prevent such runtime errors.\n\nSetting `quote-annotations` to `true` will instruct Ruff to add quotes around the annotation (e.g., `\"Sequence[int]\"`), which in turn enables Ruff to move the import into an `if TYPE_CHECKING:` block, like so:\n\n```python from typing import TYPE_CHECKING\n\nif TYPE_CHECKING: from collections.abc import Sequence\n\ndef func(value: \"Sequence[int]\") -> None: ... ```\n\nNote that this setting has no effect when `from __future__ import annotations` is present, as `__future__` annotations are always treated equivalently to quoted annotations. Similarly, this setting has no effect on Python versions after 3.14 because these annotations are also deferred.", "type": [ "boolean", "null"