Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

F841 fix since 0.0.264 can break code #4940

Closed
scop opened this issue Jun 7, 2023 · 3 comments · Fixed by #4943
Closed

F841 fix since 0.0.264 can break code #4940

scop opened this issue Jun 7, 2023 · 3 comments · Fixed by #4943
Assignees
Labels
bug Something isn't working

Comments

@scop
Copy link
Contributor

scop commented Jun 7, 2023

$ 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.

@charliermarsh
Copy link
Member

None of those should be considered "assigned but unused", right?

@charliermarsh charliermarsh added the question Asking for support or clarification label Jun 7, 2023
@scop
Copy link
Contributor Author

scop commented Jun 7, 2023

I guess so. But the code is a bit hairy, can't tell for sure on a quick skim, and unfortunately have no time right now to dig deeper.

@charliermarsh charliermarsh added bug Something isn't working and removed question Asking for support or clarification labels Jun 7, 2023
@charliermarsh
Copy link
Member

No worries. I feel like the nonlocal reads aren't being properly attributed to the scope above, or something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants