Skip to content

gh-120417: Add #noqa to load_tests() in tests - #120626

Closed
vstinner wants to merge 1 commit into
python:mainfrom
vstinner:noqa_main
Closed

gh-120417: Add #noqa to load_tests() in tests#120626
vstinner wants to merge 1 commit into
python:mainfrom
vstinner:noqa_main

Conversation

@vstinner

@vstinnervstinner commented Jun 17, 2024

Copy link
Copy Markdown
Member

Ignore linter "imported but unused" warnings in tests when the linter doesn't understand why the import is important.

@encukou

Copy link
Copy Markdown
Member

Could you add/link an explanation about what noqa: F401 means and how to maintain it?

In my projects, I've avoided these warning by adding public names to __all__, rather than with a cryptic comment.

@vstinner

Copy link
Copy Markdown
MemberAuthor

Could you add/link an explanation about what noqa: F401 means and how to maintain it?

It's a "standard" linter command to ignore "imported but unused" warning on the current line.

It was discussed at #120421.

@serhiy-storchaka

Copy link
Copy Markdown
Member

Could you add an exception for load_tests in a global configuration file?

@vstinner

Copy link
Copy Markdown
MemberAuthor

@serhiy-storchaka:

Could you add an exception for load_tests in a global configuration file?

I have no idea on how to do that.

@AlexWaygood: Is it something supported by Ruff by example?

@AlexWaygood

AlexWaygood commented Jun 17, 2024

Copy link
Copy Markdown
Member

@AlexWaygood: Is it something supported by Ruff by example?

we support ignoring certain errors for filenames that match certain patterns. But I don't think we support ignoring F401 for specific symbols, no. It might be a reasonable feature request.

@serhiy-storchaka

Copy link
Copy Markdown
Member

Can it be ignored for Lib/test/*/**/__main__.py? All these files are the same.

@AlexWaygood

Copy link
Copy Markdown
Member

Yes, in Ruff you can do that via the CLI using --config='lint.per-file-ignores = {"Lib/test/*/**/__main__.py" = ["F401"]}'. Or in a pyproject.toml configuration file, you can do this:

[tool.ruff.lint.per-file-ignores]
"Lib/test/*/**/__main__.py" = ["F401"]

Or this in a ruff.toml configuration file:

[lint.per-file-ignores]
"Lib/test/*/**/__main__.py" = ["F401"]

@vstinner

vstinner commented Jun 17, 2024

Copy link
Copy Markdown
MemberAuthor

Can it be ignored for Lib/test/*/**/__main__.py? All these files are the same.

It means that other unused imports can no longer be catched.

@vstinner

Copy link
Copy Markdown
MemberAuthor

In total, ruff check|grep F401 returns 173 lines. These load_tests are not the worst, so I prefer to close this PR for now.

@vstinner
vstinner deleted the noqa_main branch June 19, 2024 14:08
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@vstinner@encukou@serhiy-storchaka@AlexWaygood