Skip to content

gh-120417: Add #noqa: F401 to tests #120627

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
Jun 18, 2024
Merged

gh-120417: Add #noqa: F401 to tests #120627

merged 1 commit into from
Jun 18, 2024

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Jun 17, 2024

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

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import_module() can be used if ImportError is converted to SkipTest.

I have some questions about global imports of names which are seem not used in the module.

Comment on lines 104 to +106
# In case _socket fails to build, make this test fail more gracefully
# than an AttributeError somewhere deep in concurrent.futures, email
# or unittest.
import _socket
import _socket # noqa: F401
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would not using import_module() be better?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intent is to get an error if the module is missing, not to skip the test.

@@ -18,7 +18,7 @@
# compileall relies on ProcessPoolExecutor if ProcessPoolExecutor exists
# and it can function.
from multiprocessing.util import _cleanup_tests as multiprocessing_cleanup_tests
from concurrent.futures import ProcessPoolExecutor
from concurrent.futures import ProcessPoolExecutor # noqa: F401
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why ProcessPoolExecutor is needed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's explained in the comment, 2 lines above. It's a check to define _have_multiprocessing.

@@ -8,7 +8,7 @@
# of much interest anymore), and a few were fiddled to make the output
# deterministic.

from test.support import sortdict
from test.support import sortdict # noqa: F401
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why sortdict is needed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's used in doctests.

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Ignore linter "imported but unused" warnings in tests when the linter
doesn't understand why the import is important.
@vstinner
Copy link
Member Author

PR rebased to squash changes and fix merge conflicts.

@vstinner vstinner enabled auto-merge (squash) June 18, 2024 15:23
@vstinner vstinner merged commit e9f4d80 into python:main Jun 18, 2024
31 checks passed
@vstinner vstinner deleted the noqa_tests branch June 18, 2024 15:51
picnixz pushed a commit to picnixz/cpython that referenced this pull request Jun 19, 2024
Ignore linter "imported but unused" warnings in tests when the linter
doesn't understand how the import is used.
mrahtz pushed a commit to mrahtz/cpython that referenced this pull request Jun 30, 2024
Ignore linter "imported but unused" warnings in tests when the linter
doesn't understand how the import is used.
noahbkim pushed a commit to hudson-trading/cpython that referenced this pull request Jul 11, 2024
Ignore linter "imported but unused" warnings in tests when the linter
doesn't understand how the import is used.
estyxx pushed a commit to estyxx/cpython that referenced this pull request Jul 17, 2024
Ignore linter "imported but unused" warnings in tests when the linter
doesn't understand how the import is used.
Sign up for free to 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.

3 participants