Skip to content

[flake8-use-pathlib] Stabilize os-listdir (PTH208) #16642

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 12, 2025

Conversation

ntBre
Copy link
Contributor

@ntBre ntBre commented Mar 11, 2025

Summary

Stabilizes PTH208. The test was already in the right place, and the docs look good.

Test Plan

0 issues and PRs, open or closed

Summary
--

Stabilizes PTH208. The test was already in the right place, and the docs look
good.

Test Plan
--

0 issues and PRs, open or closed
@ntBre ntBre added the rule Implementing or modifying a lint rule label Mar 11, 2025
@ntBre ntBre added this to the v0.10 milestone Mar 11, 2025
Copy link

codspeed-hq bot commented Mar 11, 2025

CodSpeed Performance Report

Merging #16642 will degrade performances by 12.73%

Comparing brent/pth208-0.10 (90740b2) with micha/ruff-0.10 (85f7871)

Summary

❌ 1 regressions
✅ 31 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
red_knot_check_file[incremental] 4.8 ms 5.5 ms -12.73%

Copy link
Contributor

ruff-ecosystem results

Linter (stable)

ℹ️ ecosystem check detected linter changes. (+59 -0 violations, +0 -0 fixes in 5 projects; 50 projects unchanged)

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

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

+ dev/breeze/src/airflow_breeze/commands/release_management_commands.py:1243:17: PTH208 Use `pathlib.Path.iterdir()` instead.
+ dev/breeze/src/airflow_breeze/commands/release_management_commands.py:2284:29: PTH208 Use `pathlib.Path.iterdir()` instead.
+ dev/breeze/src/airflow_breeze/commands/sbom_commands.py:299:33: PTH208 Use `pathlib.Path.iterdir()` instead.
+ dev/breeze/src/airflow_breeze/utils/cdxgen.py:142:22: PTH208 Use `pathlib.Path.iterdir()` instead.
+ dev/check_files.py:204:13: PTH208 Use `pathlib.Path.iterdir()` instead.
+ dev/check_files.py:217:13: PTH208 Use `pathlib.Path.iterdir()` instead.
+ dev/check_files.py:230:13: PTH208 Use `pathlib.Path.iterdir()` instead.
+ devel-common/src/tests_common/test_utils/system_tests_class.py:102:17: PTH208 Use `pathlib.Path.iterdir()` instead.
+ devel-common/src/tests_common/test_utils/system_tests_class.py:86:17: PTH208 Use `pathlib.Path.iterdir()` instead.
+ docs/build_docs.py:485:20: PTH208 Use `pathlib.Path.iterdir()` instead.
+ providers/amazon/src/airflow/providers/amazon/aws/hooks/sagemaker.py:177:63: PTH208 Use `pathlib.Path.iterdir()` instead.
+ providers/openlineage/tests/unit/openlineage/plugins/test_execution.py:58:81: PTH208 Use `pathlib.Path.iterdir()` instead.
... 3 additional changes omitted for project

bokeh/bokeh (+11 -0 violations, +0 -0 fixes)

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

+ examples/server/app/simple_hdf5/main.py:19:28: PTH208 Use `pathlib.Path.iterdir()` instead.
+ src/bokeh/command/subcommands/__init__.py:54:17: PTH208 Use `pathlib.Path.iterdir()` instead.
+ src/bokeh/sphinxext/bokeh_gallery.py:134:18: PTH208 Use `pathlib.Path.iterdir()` instead.
+ src/bokeh/sphinxext/bokeh_gallery.py:160:21: PTH208 Use `pathlib.Path.iterdir()` instead.
+ src/bokeh/sphinxext/bokeh_releases.py:76:47: PTH208 Use `pathlib.Path.iterdir()` instead.
+ tests/support/util/examples.py:186:33: PTH208 Use `pathlib.Path.iterdir()` instead.
+ tests/unit/bokeh/command/subcommands/test___init___subcommands.py:48:13: PTH208 Use `pathlib.Path.iterdir()` instead.
+ tests/unit/bokeh/command/subcommands/test_json__subcommands.py:111:54: PTH208 Use `pathlib.Path.iterdir()` instead.
+ tests/unit/bokeh/command/subcommands/test_json__subcommands.py:123:50: PTH208 Use `pathlib.Path.iterdir()` instead.
+ tests/unit/bokeh/command/subcommands/test_json__subcommands.py:135:50: PTH208 Use `pathlib.Path.iterdir()` instead.
... 1 additional changes omitted for project

pypa/cibuildwheel (+4 -0 violations, +0 -0 fixes)

+ test/test_environment.py:92:16: PTH208 Use `pathlib.Path.iterdir()` instead.
+ test/test_from_sdist.py:56:16: PTH208 Use `pathlib.Path.iterdir()` instead.
+ test/test_testing.py:183:16: PTH208 Use `pathlib.Path.iterdir()` instead.
+ test/utils.py:143:18: PTH208 Use `pathlib.Path.iterdir()` instead.

reflex-dev/reflex (+1 -0 violations, +0 -0 fixes)

+ reflex/utils/prerequisites.py:1613:23: PTH208 Use `pathlib.Path.iterdir()` instead.

zulip/zulip (+28 -0 violations, +0 -0 fixes)

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

+ corporate/tests/test_stripe.py:137:18: PTH208 Use `pathlib.Path.iterdir()` instead.
+ scripts/lib/run_hooks.py:68:38: PTH208 Use `pathlib.Path.iterdir()` instead.
+ scripts/lib/zulip_tools.py:142:17: PTH208 Use `pathlib.Path.iterdir()` instead.
+ scripts/lib/zulip_tools.py:311:25: PTH208 Use `pathlib.Path.iterdir()` instead.
+ scripts/lib/zulip_tools.py:354:27: PTH208 Use `pathlib.Path.iterdir()` instead.
+ scripts/lib/zulip_tools.py:373:64: PTH208 Use `pathlib.Path.iterdir()` instead.
+ scripts/lib/zulip_tools.py:660:26: PTH208 Use `pathlib.Path.iterdir()` instead.
+ tools/documentation_crawler/documentation_crawler/spiders/check_help_documentation.py:34:29: PTH208 Use `pathlib.Path.iterdir()` instead.
+ tools/lib/test_script.py:102:34: PTH208 Use `pathlib.Path.iterdir()` instead.
+ tools/setup/generate_landing_page_images.py:29:21: PTH208 Use `pathlib.Path.iterdir()` instead.
+ tools/setup/generate_zulip_bots_static_files.py:48:20: PTH208 Use `pathlib.Path.iterdir()` instead.
+ zerver/data_import/mattermost.py:877:8: PTH208 Use `pathlib.Path.iterdir()` instead.
+ zerver/data_import/slack.py:1498:8: PTH208 Use `pathlib.Path.iterdir()` instead.
+ zerver/data_import/slack.py:840:22: PTH208 Use `pathlib.Path.iterdir()` instead.
+ zerver/lib/sounds.py:10:22: PTH208 Use `pathlib.Path.iterdir()` instead.
+ zerver/management/commands/compilemessages.py:98:23: PTH208 Use `pathlib.Path.iterdir()` instead.
+ zerver/management/commands/convert_mattermost_data.py:61:12: PTH208 Use `pathlib.Path.iterdir()` instead.
+ zerver/management/commands/convert_rocketchat_data.py:39:12: PTH208 Use `pathlib.Path.iterdir()` instead.
+ zerver/management/commands/export.py:138:20: PTH208 Use `pathlib.Path.iterdir()` instead.
+ zerver/management/commands/export_single_user.py:41:47: PTH208 Use `pathlib.Path.iterdir()` instead.
+ zerver/tests/test_delete_unclaimed_attachments.py:75:17: PTH208 Use `pathlib.Path.iterdir()` instead.
+ zerver/tests/test_delete_unclaimed_attachments.py:94:17: PTH208 Use `pathlib.Path.iterdir()` instead.
+ zerver/tests/test_import_export.py:263:30: PTH208 Use `pathlib.Path.iterdir()` instead.
... 5 additional changes omitted for project

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
PTH208 59 59 0 0 0

Linter (preview)

✅ ecosystem check detected no linter changes.

@ntBre
Copy link
Contributor Author

ntBre commented Mar 11, 2025

The ecosystem checks look like true positives. In one case there's even a call to str on a Path inside the call to os.listdir.

It might be nice to auto-fix some of these cases, but I don't think there are too many hits to accept it without a fix. A naive fix could lead to some awkward code anyway, like in the str example above (e.g. Path(str(...)).iterdir()).

I don't personally find the if cases to be a readability improvement (I like if os.listdir(p) better than if any(p.iterdir())), but I guess that's what opinionated rules are for.

@ntBre ntBre mentioned this pull request Mar 12, 2025
2 tasks
@ntBre ntBre merged commit 26cf0fe into micha/ruff-0.10 Mar 12, 2025
20 of 21 checks passed
@ntBre ntBre deleted the brent/pth208-0.10 branch March 12, 2025 12:09
MichaReiser pushed a commit that referenced this pull request Mar 13, 2025
Summary
--

Stabilizes PTH208. The test was already in the right place, and the docs
look good.

Test Plan
--

0 issues and PRs, open or closed
MichaReiser pushed a commit that referenced this pull request Mar 13, 2025
Summary
--

Stabilizes PTH208. The test was already in the right place, and the docs
look good.

Test Plan
--

0 issues and PRs, open or closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants