Skip to content

Conversation

cclauss
Copy link

@cclauss cclauss commented Aug 28, 2025

Why is this bad?

An undefined name is likely to raise NameError at runtime.

Before: % ruff check --select=F821 --output-format=concise

src/core/tests/test_validators.py:53:21: F821 Undefined name `error`
src/identifiers/logic.py:717:19: F821 Undefined name `CROSSREF_TEST_URL`
src/identifiers/logic.py:719:19: F821 Undefined name `CROSSREF_LIVE_URL`
src/metrics/views.py:1119:17: F821 Undefined name `report_months`
src/metrics/views.py:1142:17: F821 Undefined name `report_months`
src/metrics/views.py:1159:21: F821 Undefined name `report_months`
src/metrics/views.py:1176:21: F821 Undefined name `report_months`
src/press/models.py:457:33: F821 Undefined name `timezone`
src/submission/forms.py:554:21: F821 Undefined name `Q`
src/submission/forms.py:556:26: F821 Undefined name `Q`
src/submission/logic.py:336:15: F821 Undefined name `ValidationError`
src/submission/logic.py:574:15: F821 Undefined name `ValidationError`
src/submission/logic.py:605:15: F821 Undefined name `ValidationError`
src/utils/forms.py:194:19: F821 Undefined name `ImproperlyConfigured`
Found 14 errors.

After: % ruff check --select=F821 --output-format=concise # I do not see the proper fix...

src/metrics/views.py:1119:17: F821 Undefined name `report_months`
src/metrics/views.py:1142:17: F821 Undefined name `report_months`
src/metrics/views.py:1159:21: F821 Undefined name `report_months`
src/metrics/views.py:1176:21: F821 Undefined name `report_months`
Found 4 errors.

Normally, we would add report_months to the j5_tsv() function signature but that function is never called.

Should j5_tsv() be removed as dead code?


% ruff rule F821 # https://docs.astral.sh/ruff/rules/undefined-name

undefined-name (F821)

Derived from the Pyflakes linter.

What it does

Checks for uses of undefined names.

Why is this bad?

An undefined name is likely to raise NameError at runtime.

Example

def double():
    return n * 2  # raises `NameError` if `n` is undefined when `double` is called

Use instead:

def double(n):
    return n * 2

Options

  • [target-version]: Can be used to configure which symbols Ruff will understand
    as being available in the builtins namespace.

References

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