mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 14:21:53 +00:00

## Summary This is a first step toward fixing #7799 by using the quoting style stored in the `flags` field on `ast::StringLiteral`s to select a quoting style. This PR does not include support for f-strings or byte strings. Several rules also needed small updates to pass along existing quoting styles instead of using `StringLiteralFlags::default()`. The remaining snapshot changes are intentional and should preserve the quotes from the input strings. ## Test Plan Existing tests with some accepted updates, plus a few new RUF055 tests for raw strings. --------- Co-authored-by: Alex Waygood <alex.waygood@gmail.com>
92 lines
1.4 KiB
Python
92 lines
1.4 KiB
Python
import typing
|
|
from typing import Union
|
|
|
|
|
|
def f(x: Union[str, int, Union[float, bytes]]) -> None:
|
|
...
|
|
|
|
|
|
def f(x: typing.Union[str, int]) -> None:
|
|
...
|
|
|
|
|
|
def f(x: typing.Union[(str, int)]) -> None:
|
|
...
|
|
|
|
|
|
def f(x: typing.Union[(str, int), float]) -> None:
|
|
...
|
|
|
|
|
|
def f(x: typing.Union[(int,)]) -> None:
|
|
...
|
|
|
|
|
|
def f(x: typing.Union[()]) -> None:
|
|
...
|
|
|
|
|
|
def f(x: "Union[str, int, Union[float, bytes]]") -> None:
|
|
...
|
|
|
|
|
|
def f(x: "typing.Union[str, int]") -> None:
|
|
...
|
|
|
|
|
|
def f(x: Union["str", int]) -> None:
|
|
...
|
|
|
|
|
|
def f(x: Union[("str", "int"), float]) -> None:
|
|
...
|
|
|
|
|
|
def f() -> None:
|
|
x = Union[str, int]
|
|
x = Union["str", "int"]
|
|
x: Union[str, int]
|
|
x: Union["str", "int"]
|
|
|
|
|
|
def f(x: Union[int : float]) -> None:
|
|
...
|
|
|
|
|
|
def f(x: Union[str, int : float]) -> None:
|
|
...
|
|
|
|
|
|
def f(x: Union[x := int]) -> None:
|
|
...
|
|
|
|
|
|
def f(x: Union[str, x := int]) -> None:
|
|
...
|
|
|
|
|
|
def f(x: Union[lambda: int]) -> None:
|
|
...
|
|
|
|
|
|
def f(x: Union[str, lambda: int]) -> None:
|
|
...
|
|
|
|
|
|
# Regression test for: https://github.com/astral-sh/ruff/issues/7452
|
|
class Collection(Protocol[*_B0]):
|
|
def __iter__(self) -> Iterator[Union[*_B0]]:
|
|
...
|
|
|
|
|
|
# Regression test for: https://github.com/astral-sh/ruff/issues/8609
|
|
def f(x: Union[int, str, bytes]) -> None:
|
|
...
|
|
|
|
|
|
# Regression test for https://github.com/astral-sh/ruff/issues/14132
|
|
class AClass:
|
|
...
|
|
|
|
def myfunc(param: "tuple[Union[int, 'AClass', None], str]"):
|
|
print(param)
|