mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 13:51:37 +00:00
![]() ## Summary The use of `|` as a union operator is not always safe, if a type annotation is evaluated in a runtime context. For example, this code errors at runtime: ```python import httpretty import requests_mock item: type[requests_mock.Mocker | httpretty] = requests_mock.Mocker ``` However, it's fine in a `.pyi` file, with `__future__` annotations`, or if the annotation is in a non-evaluated context, like: ```python def func(): item: type[requests_mock.Mocker | httpretty] = requests_mock.Mocker ``` This PR modifies the rule to avoid enforcing in those invalid, runtime-evaluated contexts. Closes https://github.com/astral-sh/ruff/issues/6455. |
||
---|---|---|
.. | ||
flake8_to_ruff | ||
ruff | ||
ruff_benchmark | ||
ruff_cache | ||
ruff_cli | ||
ruff_dev | ||
ruff_diagnostics | ||
ruff_formatter | ||
ruff_index | ||
ruff_macros | ||
ruff_python_ast | ||
ruff_python_codegen | ||
ruff_python_formatter | ||
ruff_python_index | ||
ruff_python_literal | ||
ruff_python_parser | ||
ruff_python_resolver | ||
ruff_python_semantic | ||
ruff_python_stdlib | ||
ruff_python_trivia | ||
ruff_shrinking | ||
ruff_source_file | ||
ruff_text_size | ||
ruff_wasm |