Summary
This pyproject.yaml:
[tool.ruff]
target-version = "py310"
[tool.ruff.lint]
select = ["UP"]
and running ruff check --fix file.py on this example:
from typing import Optional
def a() -> Optional[str]:
return None
results in:
from typing import Optional
def a() -> str | None:
return None
so Ruff has updated the type signature, but left the import.
Trying to figure out if my expectations are wrong, the documentation at https://docs.astral.sh/ruff/rules/non-pep604-annotation-union/#fix-safety says:
This rule's fix is marked as unsafe, as it may lead to runtime errors when alongside libraries that rely on runtime type annotations, like Pydantic, on Python versions prior to Python 3.10.
which I believe is contradictory to being able to use --fix, unsafe rules require enabling some other switch.
Edit: the phrasing "it may lead to runtime errors when alongside libraries" is also confusing to me; what is alongside the libraries, the fix?
Version
ruff 0.11.2
Summary
This pyproject.yaml:
and running
ruff check --fix file.pyon this example:results in:
so Ruff has updated the type signature, but left the import.
Trying to figure out if my expectations are wrong, the documentation at https://docs.astral.sh/ruff/rules/non-pep604-annotation-union/#fix-safety says:
which I believe is contradictory to being able to use
--fix, unsafe rules require enabling some other switch.Edit: the phrasing "it may lead to runtime errors when alongside libraries" is also confusing to me; what is alongside the libraries, the fix?
Version
ruff 0.11.2