mirror of https://github.com/astral-sh/ruff
Update `lint.flake8-type-checking.quoted-annotations` docs (#20765)
Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
parent
5e08e5451d
commit
e338d2095e
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Reference in New Issue