mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-27 04:19:18 +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. |
||
---|---|---|
.. | ||
resources/test | ||
src | ||
Cargo.toml |