Skip to content

Form feeds make the RUF072 fix introduce syntax errors #24246

@dscorbett

Description

@dscorbett

Summary

The useless-finally (RUF072) fix introduces a syntax error when it dedents a try block some but not all of whose lines begin with form feeds.

$ printf 'try:\n\f    1\n    2\nfinally:\n    pass\n' >ruf072.py

$ ruff --isolated check ruf072.py --select RUF072 --preview --fix

error: Fix introduced a syntax error. Reverting all changes.

This indicates a bug in Ruff. If you could open an issue at:

    https://github.com/astral-sh/ruff/issues/new?title=%5BFix%20error%5D

...quoting the contents of `ruf072.py`, the rule codes RUF072, along with the `pyproject.toml` settings and executed command, we'd be very appreciative!

error[RUF072]: Empty `finally` clause
 --> ruf072.py:4:1
  |
2 |       1
3 |       2
4 | / finally:
5 | |     pass
  | |________^
  |
help: Remove the `finally` clause
  - try:
  -     1
1 + 1
2 |     2
  - finally:
  -     pass

Found 1 error.
[*] 1 fixable with the `--fix` option.

Version

ruff 0.15.8 (c2a8815 2026-03-26)

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingfixesRelated to suggested fixes for violations

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions