Skip to content

Conversation

@dylwil3
Copy link
Collaborator

@dylwil3 dylwil3 commented Oct 15, 2025

Closes #20839

@dylwil3 dylwil3 added bug Something isn't working rule Implementing or modifying a lint rule preview Related to preview mode features labels Oct 15, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Oct 15, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+0 -22 violations, +0 -0 fixes in 6 projects; 49 projects unchanged)

RasaHQ/rasa (+0 -1 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview

- rasa/utils/plotting.py:35:20: F401 `tkinter` imported but unused; consider using `importlib.util.find_spec` to test for availability

apache/airflow (+0 -7 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview --select ALL

- devel-common/src/tests_common/pytest_plugin.py:2164:16: F401 `airflow.sdk._shared.logging` imported but unused; consider using `importlib.util.find_spec` to test for availability
- devel-common/src/tests_common/pytest_plugin.py:2167:20: F401 `airflow.sdk._shared.logging` imported but unused; consider using `importlib.util.find_spec` to test for availability
- providers/celery/src/airflow/providers/celery/executors/celery_executor_utils.py:120:16: F401 [*] `airflow.jobs.local_task_job_runner` imported but unused
- providers/celery/src/airflow/providers/celery/executors/celery_executor_utils.py:121:16: F401 [*] `airflow.macros` imported but unused
- providers/celery/src/airflow/providers/celery/executors/celery_executor_utils.py:124:16: F401 `airflow.providers.standard.operators.bash` imported but unused; consider using `importlib.util.find_spec` to test for availability
- providers/celery/src/airflow/providers/celery/executors/celery_executor_utils.py:125:16: F401 `airflow.providers.standard.operators.python` imported but unused; consider using `importlib.util.find_spec` to test for availability
- providers/celery/src/airflow/providers/celery/executors/celery_executor_utils.py:127:16: F401 [*] `airflow.operators.bash` imported but unused

binary-husky/gpt_academic (+0 -1 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview

- crazy_functions/Multi_Agent_Legacy.py:57:16: F401 [*] `autogen` imported but unused

mlflow/mlflow (+0 -10 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview

- tests/utils/test_model_utils.py:74:20: F401 [*] `dummy_module` imported but unused
- tests/utils/test_requirements_utils.py:320:16: F401 [*] `databricks` imported but unused
- tests/utils/test_requirements_utils.py:321:16: F401 [*] `databricks.automl` imported but unused
- tests/utils/test_requirements_utils.py:322:16: F401 [*] `databricks.automl_foo` imported but unused
- tests/utils/test_requirements_utils.py:323:16: F401 [*] `databricks.automl_runtime` imported but unused
- tests/utils/test_requirements_utils.py:324:16: F401 [*] `databricks.model_monitoring` imported but unused
- tests/utils/test_requirements_utils.py:332:16: F401 [*] `databricks.automl` imported but unused
- tests/utils/test_requirements_utils.py:333:16: F401 [*] `databricks.automl_foo` imported but unused
- tests/utils/test_requirements_utils.py:334:16: F401 [*] `databricks.automl_runtime` imported but unused
- tests/utils/test_requirements_utils.py:335:16: F401 [*] `databricks.model_monitoring` imported but unused

scikit-build/scikit-build (+0 -2 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview

- skbuild/utils/__init__.py:33:12: F401 `setuptools.logging` imported but unused; consider using `importlib.util.find_spec` to test for availability
- tests/__init__.py:9:12: F401 `distutils` imported but unused

mesonbuild/meson-python (+0 -1 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview

- tests/test_editable.py:281:24: F401 [*] `pure` imported but unused

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
F401 22 0 22 0 0

@dylwil3
Copy link
Collaborator Author

dylwil3 commented Oct 17, 2025

The ecosystem hits look correct - these two are debatable, but keeping the stable behavior seems fine for now:

@dylwil3 dylwil3 marked this pull request as ready for review October 17, 2025 17:48
@MichaReiser
Copy link
Member

MichaReiser commented Oct 20, 2025

The examples with if TYPE_CHECKING are a bit unfortunate. Do you think it would be possible to instead test if the import is in an alternate branch than the other import?

E.g. the following should be flagged

if True:
	import a.b
	if other:
		import a.b

but not

if True:
	import a.b
else:
	if other:
		import a.b

So, I guess, we'd have to check if the first import ancestor chain is a prefix of the second import's ancestor chain

@dylwil3 dylwil3 changed the title [pyflakes] Revert to stable behavior if imports for module lie in different branches for F401 [pyflakes] Revert to stable behavior if imports for module lie in alternate branches for F401 Oct 24, 2025
@MichaReiser
Copy link
Member

Did this new approach improve the ecosystem results?

@dylwil3
Copy link
Collaborator Author

dylwil3 commented Oct 27, 2025

Did this new approach improve the ecosystem results?

Yes! The things that remain are variations on the try/except pattern in the original issue.

@dylwil3 dylwil3 merged commit fffbe5a into astral-sh:main Oct 27, 2025
37 checks passed
dcreager added a commit that referenced this pull request Oct 27, 2025
* origin/main:
  Respect `--output-format` with `--watch` (#21097)
  [`pyflakes`] Revert to stable behavior if imports for module lie in alternate branches for `F401` (#20878)
  Fix finding keyword range for clause header after statement ending with semicolon (#21067)
  [ty] Fix bug where ty would think all types had an `__mro__` attribute (#20995)
  Restore `indent.py` (#21094)
  [`flake8-django`] Apply `DJ001` to annotated fields (#20907)
  Clearer error message when `line-length` goes beyond threshold (#21072)
  Update upload and download artifacts github actions (#21083)
  Update dependency mdformat-mkdocs to v4.4.2 (#21088)
  Update cargo-bins/cargo-binstall action to v1.15.9 (#21086)
  Update Rust crate clap to v4.5.50 (#21090)
  Update Rust crate get-size2 to v0.7.1 (#21091)
  Update Rust crate bstr to v1.12.1 (#21089)
  Add missing docstring sections to the numpy list (#20931)
  [`pydoclint`] Fix false positive on explicit exception re-raising (`DOC501`, `DOC502`) (#21011)
  [ty] Use constructor parameter types as type context (#21054)
@dylwil3 dylwil3 deleted the f401-branches branch October 28, 2025 12:57
dcreager added a commit that referenced this pull request Oct 28, 2025
…l-constraint-sets

* dcreager/refactor-constraint-mdtests: (60 commits)
  add static_asserts
  move all reveal diagnostics to separate line
  add more gradual tests
  better comment
  restructure a bit
  better names/comments
  simplify before implication
  two typevars!
  mdformat
  rename mdtest
  move is_subtype_of_given into ConstraintSet
  move where we grab these
  add ConstraintSet.{always,never}
  move range_constraint into ConstraintSet class
  [ty] Rename `inner` query for better debugging experience (#21106)
  [ty] Add new "constraint implication" typing relation (#21010)
  [semantic error tests]: refactor semantic error tests to separate files (#20926)
  Respect `--output-format` with `--watch` (#21097)
  [`pyflakes`] Revert to stable behavior if imports for module lie in alternate branches for `F401` (#20878)
  Fix finding keyword range for clause header after statement ending with semicolon (#21067)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working preview Related to preview mode features rule Implementing or modifying a lint rule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

F401: false positive causes NameError

2 participants