Skip to content

add warning for unused global / nonlocal names #825

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

Merged
merged 1 commit into from
Mar 29, 2025

Conversation

asottile
Copy link
Member

some example output from a work codebase:

$ flake8  src/ tests/
src/sentry/backup/imports.py:397:9: F999 `nonlocal deferred_org_auth_tokens` is unused: name is never assigned in scope
src/sentry/backup/imports.py:397:9: F999 `nonlocal import_write_context` is unused: name is never assigned in scope
src/sentry/llm/usecases/__init__.py:29:5: F999 `global llm_provider_backends` is unused: name is never assigned in scope
src/sentry/runner/commands/workstations.py:191:13: F999 `nonlocal proc` is unused: name is never assigned in scope
src/sentry/runner/commands/workstations.py:191:13: F999 `nonlocal silence_stderr` is unused: name is never assigned in scope
src/sentry/taskworker/worker.py:95:9: F999 `nonlocal current_activation` is unused: name is never assigned in scope
src/sentry/taskworker/worker.py:95:9: F999 `nonlocal processed_tasks` is unused: name is never assigned in scope
src/sentry/utils/mockdata/core.py:941:17: F999 `nonlocal timestamp` is unused: name is never assigned in scope
src/sentry/utils/mockdata/core.py:1188:17: F999 `nonlocal timestamp` is unused: name is never assigned in scope
src/sentry/utils/mockdata/core.py:1189:17: F999 `nonlocal duration` is unused: name is never assigned in scope
src/social_auth/backends/__init__.py:731:5: F999 `global BACKENDSCACHE` is unused: name is never assigned in scope
tests/sentry/backup/test_rpc.py:57:13: F999 `nonlocal option_count` is unused: name is never assigned in scope
tests/sentry/backup/test_rpc.py:57:13: F999 `nonlocal import_chunk_count` is unused: name is never assigned in scope
tests/sentry/backup/test_rpc.py:57:13: F999 `nonlocal import_uuid` is unused: name is never assigned in scope
tests/sentry/backup/test_rpc.py:134:13: F999 `nonlocal control_option_count` is unused: name is never assigned in scope
tests/sentry/backup/test_rpc.py:134:13: F999 `nonlocal import_chunk_count` is unused: name is never assigned in scope
tests/sentry/backup/test_rpc.py:134:13: F999 `nonlocal import_uuid` is unused: name is never assigned in scope
tests/sentry/hybridcloud/rpc/test_caching.py:129:9: F999 `nonlocal true_value` is unused: name is never assigned in scope

@asottile asottile requested a review from Copilot March 29, 2025 18:56
Copilot

This comment was marked as off-topic.

@asottile asottile merged commit cadcd60 into main Mar 29, 2025
9 checks passed
@asottile asottile deleted the unused-global-nonlocal branch March 29, 2025 19:13
fnordahl added a commit to fnordahl/ovs that referenced this pull request Mar 30, 2025
…heck (F824).

flake8 2.7.0 introduced the F824 check [0].

While the check sounds reasonable on the surface, we have code in
the repository where the global variable is used only for access.

My conclusion from evaluating the alternative of adjusting the code
to appease the check is that it would invite future mistakes where
the global variable is unintentionally shadowed in addition to
making the code less clear and explicit.

0: PyCQA/flake8#1974
1: PyCQA/pyflakes#825
Signed-off-by: Frode Nordahl <[email protected]>
ovsrobot pushed a commit to ovsrobot/ovs that referenced this pull request Mar 30, 2025
…heck (F824).

flake8 2.7.0 introduced the F824 check [0].

While the check sounds reasonable on the surface, we have code in
the repository where the global variable is used only for access.

My conclusion from evaluating the alternative of adjusting the code
to appease the check is that it would invite future mistakes where
the global variable is unintentionally shadowed in addition to
making the code less clear and explicit.

0: PyCQA/flake8#1974
1: PyCQA/pyflakes#825
Signed-off-by: Frode Nordahl <[email protected]>
Signed-off-by: 0-day Robot <[email protected]>
igsilya pushed a commit to igsilya/ovs that referenced this pull request Mar 30, 2025
flake8 2.7.0 introduced the F824 check [0].

While the check sounds reasonable on the surface, we have code in
the repository where the global variable is used only for access.

My conclusion from evaluating the alternative of adjusting the code
to appease the check is that it would invite future mistakes where
the global variable is unintentionally shadowed in addition to
making the code less clear and explicit.

0: PyCQA/flake8#1974
1: PyCQA/pyflakes#825
Signed-off-by: Frode Nordahl <[email protected]>
Signed-off-by: Ilya Maximets <[email protected]>
igsilya pushed a commit to igsilya/ovs that referenced this pull request Mar 30, 2025
flake8 2.7.0 introduced the F824 check [0].

While the check sounds reasonable on the surface, we have code in
the repository where the global variable is used only for access.

My conclusion from evaluating the alternative of adjusting the code
to appease the check is that it would invite future mistakes where
the global variable is unintentionally shadowed in addition to
making the code less clear and explicit.

0: PyCQA/flake8#1974
1: PyCQA/pyflakes#825
Signed-off-by: Frode Nordahl <[email protected]>
Signed-off-by: Ilya Maximets <[email protected]>
igsilya pushed a commit to igsilya/ovs that referenced this pull request Mar 30, 2025
flake8 2.7.0 introduced the F824 check [0].

While the check sounds reasonable on the surface, we have code in
the repository where the global variable is used only for access.

My conclusion from evaluating the alternative of adjusting the code
to appease the check is that it would invite future mistakes where
the global variable is unintentionally shadowed in addition to
making the code less clear and explicit.

0: PyCQA/flake8#1974
1: PyCQA/pyflakes#825
Signed-off-by: Frode Nordahl <[email protected]>
Signed-off-by: Ilya Maximets <[email protected]>
igsilya pushed a commit to igsilya/ovs that referenced this pull request Mar 30, 2025
flake8 2.7.0 introduced the F824 check [0].

While the check sounds reasonable on the surface, we have code in
the repository where the global variable is used only for access.

My conclusion from evaluating the alternative of adjusting the code
to appease the check is that it would invite future mistakes where
the global variable is unintentionally shadowed in addition to
making the code less clear and explicit.

0: PyCQA/flake8#1974
1: PyCQA/pyflakes#825
Signed-off-by: Frode Nordahl <[email protected]>
Signed-off-by: Ilya Maximets <[email protected]>
igsilya pushed a commit to igsilya/ovs that referenced this pull request Mar 30, 2025
flake8 2.7.0 introduced the F824 check [0].

While the check sounds reasonable on the surface, we have code in
the repository where the global variable is used only for access.

My conclusion from evaluating the alternative of adjusting the code
to appease the check is that it would invite future mistakes where
the global variable is unintentionally shadowed in addition to
making the code less clear and explicit.

0: PyCQA/flake8#1974
1: PyCQA/pyflakes#825
Signed-off-by: Frode Nordahl <[email protected]>
Signed-off-by: Ilya Maximets <[email protected]>
fnordahl added a commit to fnordahl/ovn that referenced this pull request Mar 31, 2025
Building the OVS submodule is currently broken for the OVN CI due
to a change in flake8 2.7.0 which introduced the F824 check [0][1].

This was tackled in OVS commit 7f4ee4395637 by disabling the check.

0: PyCQA/flake8#1974
1: PyCQA/pyflakes#825
Signed-off-by: Frode Nordahl <[email protected]>
ovsrobot pushed a commit to ovsrobot/ovn that referenced this pull request Mar 31, 2025
Building the OVS submodule is currently broken for the OVN CI due
to a change in flake8 2.7.0 which introduced the F824 check [0][1].

This was tackled in OVS commit 7f4ee4395637 by disabling the check.

0: PyCQA/flake8#1974
1: PyCQA/pyflakes#825
Signed-off-by: Frode Nordahl <[email protected]>
Signed-off-by: 0-day Robot <[email protected]>
dceara pushed a commit to dceara/ovn that referenced this pull request Mar 31, 2025
Building the OVS submodule is currently broken for the OVN CI due
to a change in flake8 2.7.0 which introduced the F824 check [0][1].

This was tackled in OVS commit 7f4ee4395637 by disabling the check.

0: PyCQA/flake8#1974
1: PyCQA/pyflakes#825
Signed-off-by: Frode Nordahl <[email protected]>
Acked-by: Ales Musil <[email protected]>
Signed-off-by: Dumitru Ceara <[email protected]>
dceara pushed a commit to dceara/ovn that referenced this pull request Mar 31, 2025
Building the OVS submodule is currently broken for the OVN CI due
to a change in flake8 2.7.0 which introduced the F824 check [0][1].

This was tackled in OVS commit 7f4ee4395637 by disabling the check.

0: PyCQA/flake8#1974
1: PyCQA/pyflakes#825
Signed-off-by: Frode Nordahl <[email protected]>
Acked-by: Ales Musil <[email protected]>
Signed-off-by: Dumitru Ceara <[email protected]>
(cherry picked from commit 94c8a4c)
dceara pushed a commit to dceara/ovn that referenced this pull request Mar 31, 2025
Building the OVS submodule is currently broken for the OVN CI due
to a change in flake8 2.7.0 which introduced the F824 check [0][1].

This was tackled in OVS commit 7f4ee4395637 by disabling the check.

0: PyCQA/flake8#1974
1: PyCQA/pyflakes#825
Signed-off-by: Frode Nordahl <[email protected]>
Acked-by: Ales Musil <[email protected]>
Signed-off-by: Dumitru Ceara <[email protected]>
(cherry picked from commit 94c8a4c)
dceara pushed a commit to dceara/ovn that referenced this pull request Mar 31, 2025
Building the OVS submodule is currently broken for the OVN CI due
to a change in flake8 2.7.0 which introduced the F824 check [0][1].

This was tackled in OVS commit 7f4ee4395637 by disabling the check.

0: PyCQA/flake8#1974
1: PyCQA/pyflakes#825
Signed-off-by: Frode Nordahl <[email protected]>
Acked-by: Ales Musil <[email protected]>
Signed-off-by: Dumitru Ceara <[email protected]>
(cherry picked from commit 94c8a4c)
dceara pushed a commit to dceara/ovn that referenced this pull request Mar 31, 2025
Building the OVS submodule is currently broken for the OVN CI due
to a change in flake8 2.7.0 which introduced the F824 check [0][1].

This was tackled in OVS commit 7f4ee4395637 by disabling the check.

0: PyCQA/flake8#1974
1: PyCQA/pyflakes#825
Signed-off-by: Frode Nordahl <[email protected]>
Acked-by: Ales Musil <[email protected]>
Signed-off-by: Dumitru Ceara <[email protected]>
dceara pushed a commit to dceara/ovn that referenced this pull request Mar 31, 2025
Building the OVS submodule is currently broken for the OVN CI due
to a change in flake8 2.7.0 which introduced the F824 check [0][1].

This was tackled in OVS commit 7f4ee4395637 by disabling the check.

0: PyCQA/flake8#1974
1: PyCQA/pyflakes#825
Signed-off-by: Frode Nordahl <[email protected]>
Acked-by: Ales Musil <[email protected]>
Signed-off-by: Dumitru Ceara <[email protected]>
(cherry picked from commit f68cc0c)
dceara pushed a commit to dceara/ovn that referenced this pull request Mar 31, 2025
Building the OVS submodule is currently broken for the OVN CI due
to a change in flake8 2.7.0 which introduced the F824 check [0][1].

This was tackled in OVS commit 7f4ee4395637 by disabling the check.

0: PyCQA/flake8#1974
1: PyCQA/pyflakes#825
Signed-off-by: Frode Nordahl <[email protected]>
Acked-by: Ales Musil <[email protected]>
Signed-off-by: Dumitru Ceara <[email protected]>
(cherry picked from commit f68cc0c)
dceara pushed a commit to dceara/ovn that referenced this pull request Mar 31, 2025
Building the OVS submodule is currently broken for the OVN CI due
to a change in flake8 2.7.0 which introduced the F824 check [0][1].

This was tackled in OVS commit 7f4ee4395637 by disabling the check.

0: PyCQA/flake8#1974
1: PyCQA/pyflakes#825
Signed-off-by: Frode Nordahl <[email protected]>
Acked-by: Ales Musil <[email protected]>
Signed-off-by: Dumitru Ceara <[email protected]>
(cherry picked from commit f68cc0c)
parthosa added a commit to NVIDIA/spark-rapids-tools that referenced this pull request Apr 2, 2025
Fixes #1608.

This PR fixes the code for a new warning added in the newly released
flake8: PyCQA/pyflakes#825.

---------

Signed-off-by: Partho Sarthi <[email protected]>
mdickinson added a commit to enthought/traits that referenced this pull request Apr 11, 2025
A recent release of `flake8` started complaining about redundant uses of
`global` inside functions/methods, causing `flake8` errors in the Traits
style checks. (The relevant change is in pyflakes 3.3.0: see
PyCQA/pyflakes#825.)

This PR removes those `global` declarations.
martinmo pushed a commit to martinmo/ovs that referenced this pull request Apr 22, 2025
flake8 2.7.0 introduced the F824 check [0].

While the check sounds reasonable on the surface, we have code in
the repository where the global variable is used only for access.

My conclusion from evaluating the alternative of adjusting the code
to appease the check is that it would invite future mistakes where
the global variable is unintentionally shadowed in addition to
making the code less clear and explicit.

0: PyCQA/flake8#1974
1: PyCQA/pyflakes#825
Signed-off-by: Frode Nordahl <[email protected]>
Signed-off-by: Ilya Maximets <[email protected]>
(cherry picked from commit 7f4ee43)
amorenoz pushed a commit to amorenoz/ovs that referenced this pull request May 13, 2025
flake8 2.7.0 introduced the F824 check [0].

While the check sounds reasonable on the surface, we have code in
the repository where the global variable is used only for access.

My conclusion from evaluating the alternative of adjusting the code
to appease the check is that it would invite future mistakes where
the global variable is unintentionally shadowed in addition to
making the code less clear and explicit.

0: PyCQA/flake8#1974
1: PyCQA/pyflakes#825
Signed-off-by: Frode Nordahl <[email protected]>
Signed-off-by: Ilya Maximets <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant