Skip to content

F841 fix since 0.0.264 can break code #4940

@scop

Description

@scop
$ curl -O https://raw.githubusercontent.com/home-assistant/core/03710e58b5cc3cd1e2472d2e497bf5780695eca5/tests/components/homekit_controller/test_init.py
$ ruff test_init.py
test_init.py:150:5: F841 [*] Local variable `is_connected` is assigned to but never used
test_init.py:218:5: F841 [*] Local variable `is_available` is assigned to but never used
Found 2 errors.
[*] 2 potentially fixable with the --fix option.
$ ruff --fix test_init.py
Found 6 errors (6 fixed, 0 remaining).

Note found 2 vs 6 errors. After the --fix:

$ python3 -m test_init
Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 185, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/usr/lib/python3.8/runpy.py", line 155, in _get_module_details
    code = loader.get_code(mod_name)
  File "<frozen importlib._bootstrap_external>", line 981, in get_code
  File "<frozen importlib._bootstrap_external>", line 911, in source_to_code
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File ".../test_init.py", line 116
    nonlocal is_connected
    ^
SyntaxError: no binding for nonlocal 'is_connected' found

Haven't actually checked, but I suppose the fix for these issues is removing too many of the same named variables, not only the two it flagged errors for in non-fix mode.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions