Skip to content

Conversation

@chirizxc
Copy link
Contributor

@chirizxc chirizxc commented Aug 30, 2025

Summary

Part of #2331

Test Plan

cargo nextest run flake8_use_pathlib

@github-actions
Copy link
Contributor

github-actions bot commented Aug 30, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

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

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

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

+ airflow-core/src/airflow/api_fastapi/auth/managers/simple/simple_auth_manager.py:107:14: PTH123 [*] `open()` should be replaced by `Path.open()`
- airflow-core/src/airflow/api_fastapi/auth/managers/simple/simple_auth_manager.py:107:14: PTH123 `open()` should be replaced by `Path.open()`
+ airflow-core/src/airflow/api_fastapi/auth/managers/simple/simple_auth_manager.py:118:18: PTH123 [*] `open()` should be replaced by `Path.open()`
- airflow-core/src/airflow/api_fastapi/auth/managers/simple/simple_auth_manager.py:118:18: PTH123 `open()` should be replaced by `Path.open()`
+ airflow-core/src/airflow/api_fastapi/auth/tokens.py:166:18: PTH123 [*] `open()` should be replaced by `Path.open()`
- airflow-core/src/airflow/api_fastapi/auth/tokens.py:166:18: PTH123 `open()` should be replaced by `Path.open()`
+ airflow-core/src/airflow/api_fastapi/auth/tokens.py:370:10: PTH123 [*] `open()` should be replaced by `Path.open()`
- airflow-core/src/airflow/api_fastapi/auth/tokens.py:370:10: PTH123 `open()` should be replaced by `Path.open()`
+ airflow-core/src/airflow/cli/commands/config_command.py:1063:14: PTH123 [*] `open()` should be replaced by `Path.open()`
- airflow-core/src/airflow/cli/commands/config_command.py:1063:14: PTH123 `open()` should be replaced by `Path.open()`
+ airflow-core/src/airflow/cli/commands/daemon_utils.py:64:14: PTH123 [*] `open()` should be replaced by `Path.open()`
- airflow-core/src/airflow/cli/commands/daemon_utils.py:64:14: PTH123 `open()` should be replaced by `Path.open()`
+ airflow-core/src/airflow/cli/commands/daemon_utils.py:64:50: PTH123 [*] `open()` should be replaced by `Path.open()`
- airflow-core/src/airflow/cli/commands/daemon_utils.py:64:50: PTH123 `open()` should be replaced by `Path.open()`
+ airflow-core/src/airflow/cli/commands/pool_command.py:117:10: PTH123 [*] `open()` should be replaced by `Path.open()`
- airflow-core/src/airflow/cli/commands/pool_command.py:117:10: PTH123 `open()` should be replaced by `Path.open()`
+ airflow-core/src/airflow/cli/commands/pool_command.py:147:10: PTH123 [*] `open()` should be replaced by `Path.open()`
- airflow-core/src/airflow/cli/commands/pool_command.py:147:10: PTH123 `open()` should be replaced by `Path.open()`
+ airflow-core/src/airflow/configuration.py:194:14: PTH123 [*] `open()` should be replaced by `Path.open()`
- airflow-core/src/airflow/configuration.py:194:14: PTH123 `open()` should be replaced by `Path.open()`
+ airflow-core/src/airflow/configuration.py:2077:14: PTH123 [*] `open()` should be replaced by `Path.open()`
- airflow-core/src/airflow/configuration.py:2077:14: PTH123 `open()` should be replaced by `Path.open()`
+ airflow-core/src/airflow/dag_processing/bundles/base.py:168:18: PTH123 [*] `open()` should be replaced by `Path.open()`
- airflow-core/src/airflow/dag_processing/bundles/base.py:168:18: PTH123 `open()` should be replaced by `Path.open()`
... 788 additional changes omitted for project

apache/superset (+0 -0 violations, +64 -0 fixes)

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

+ RELEASING/changelog.py:391:14: PTH123 [*] `open()` should be replaced by `Path.open()`
- RELEASING/changelog.py:391:14: PTH123 `open()` should be replaced by `Path.open()`
+ RELEASING/generate_email.py:51:32: PTH123 [*] `open()` should be replaced by `Path.open()`
- RELEASING/generate_email.py:51:32: PTH123 `open()` should be replaced by `Path.open()`
+ RELEASING/verify_release.py:39:10: PTH123 [*] `open()` should be replaced by `Path.open()`
- RELEASING/verify_release.py:39:10: PTH123 `open()` should be replaced by `Path.open()`
+ scripts/change_detector.py:142:10: PTH123 [*] `open()` should be replaced by `Path.open()`
- scripts/change_detector.py:142:10: PTH123 `open()` should be replaced by `Path.open()`
+ scripts/erd/erd.py:179:10: PTH123 [*] `open()` should be replaced by `Path.open()`
- scripts/erd/erd.py:179:10: PTH123 `open()` should be replaced by `Path.open()`
... 54 additional changes omitted for project

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

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

+ docs/bokeh/source/conf.py:69:14: PTH123 [*] `open()` should be replaced by `Path.open()`
- docs/bokeh/source/conf.py:69:14: PTH123 `open()` should be replaced by `Path.open()`
+ examples/models/basic_plot.py:42:10: PTH123 [*] `open()` should be replaced by `Path.open()`
- examples/models/basic_plot.py:42:10: PTH123 `open()` should be replaced by `Path.open()`
+ examples/models/buttons.py:75:10: PTH123 [*] `open()` should be replaced by `Path.open()`
- examples/models/buttons.py:75:10: PTH123 `open()` should be replaced by `Path.open()`
+ examples/models/calendars.py:104:10: PTH123 [*] `open()` should be replaced by `Path.open()`
- examples/models/calendars.py:104:10: PTH123 `open()` should be replaced by `Path.open()`
+ examples/models/colors.py:69:10: PTH123 [*] `open()` should be replaced by `Path.open()`
- examples/models/colors.py:69:10: PTH123 `open()` should be replaced by `Path.open()`
... 178 additional changes omitted for project

latchbio/latch (+0 -0 violations, +36 -0 fixes)

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

+ src/latch/executions.py:56:14: PTH123 [*] `open()` should be replaced by `Path.open()`
- src/latch/executions.py:56:14: PTH123 `open()` should be replaced by `Path.open()`
+ src/latch/ldata/_transfer/download.py:229:10: PTH123 [*] `open()` should be replaced by `Path.open()`
- src/latch/ldata/_transfer/download.py:229:10: PTH123 `open()` should be replaced by `Path.open()`
+ src/latch/ldata/_transfer/upload.py:329:14: PTH123 [*] `open()` should be replaced by `Path.open()`
- src/latch/ldata/_transfer/upload.py:329:14: PTH123 `open()` should be replaced by `Path.open()`
+ src/latch/ldata/_transfer/upload.py:424:14: PTH123 [*] `open()` should be replaced by `Path.open()`
- src/latch/ldata/_transfer/upload.py:424:14: PTH123 `open()` should be replaced by `Path.open()`
+ src/latch_cli/exceptions/traceback.py:24:14: PTH123 [*] `open()` should be replaced by `Path.open()`
- src/latch_cli/exceptions/traceback.py:24:14: PTH123 `open()` should be replaced by `Path.open()`
... 26 additional changes omitted for project

milvus-io/pymilvus (+0 -0 violations, +8 -0 fixes)

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

+ examples/orm_deprecated/bulk_import/example_bulkinsert_csv.py:114:10: PTH123 [*] `open()` should be replaced by `Path.open()`
- examples/orm_deprecated/bulk_import/example_bulkinsert_csv.py:114:10: PTH123 `open()` should be replaced by `Path.open()`
+ examples/orm_deprecated/bulk_import/example_bulkinsert_json.py:147:10: PTH123 [*] `open()` should be replaced by `Path.open()`
- examples/orm_deprecated/bulk_import/example_bulkinsert_json.py:147:10: PTH123 `open()` should be replaced by `Path.open()`
+ examples/orm_deprecated/bulk_import/example_bulkinsert_withfunction.py:116:10: PTH123 [*] `open()` should be replaced by `Path.open()`
- examples/orm_deprecated/bulk_import/example_bulkinsert_withfunction.py:116:10: PTH123 `open()` should be replaced by `Path.open()`
+ examples/orm_deprecated/bulk_import/example_bulkwriter.py:210:18: PTH123 [*] `open()` should be replaced by `Path.open()`
- examples/orm_deprecated/bulk_import/example_bulkwriter.py:210:18: PTH123 `open()` should be replaced by `Path.open()`

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

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

+ analytics/management/commands/populate_analytics_db.py:146:14: PTH123 [*] `open()` should be replaced by `Path.open()`
- analytics/management/commands/populate_analytics_db.py:146:14: PTH123 `open()` should be replaced by `Path.open()`
+ corporate/tests/test_stripe.py:156:18: PTH123 [*] `open()` should be replaced by `Path.open()`
- corporate/tests/test_stripe.py:156:18: PTH123 `open()` should be replaced by `Path.open()`
+ corporate/tests/test_stripe.py:169:14: PTH123 [*] `open()` should be replaced by `Path.open()`
- corporate/tests/test_stripe.py:169:14: PTH123 `open()` should be replaced by `Path.open()`
+ corporate/tests/test_stripe.py:187:14: PTH123 [*] `open()` should be replaced by `Path.open()`
- corporate/tests/test_stripe.py:187:14: PTH123 `open()` should be replaced by `Path.open()`
+ corporate/tests/test_stripe.py:280:14: PTH123 [*] `open()` should be replaced by `Path.open()`
- corporate/tests/test_stripe.py:280:14: PTH123 `open()` should be replaced by `Path.open()`
+ corporate/tests/test_stripe.py:306:14: PTH123 [*] `open()` should be replaced by `Path.open()`
- corporate/tests/test_stripe.py:306:14: PTH123 `open()` should be replaced by `Path.open()`
+ corporate/views/portico.py:286:14: PTH123 [*] `open()` should be replaced by `Path.open()`
- corporate/views/portico.py:286:14: PTH123 `open()` should be replaced by `Path.open()`
+ scripts/lib/check_rabbitmq_queue.py:194:14: PTH123 [*] `open()` should be replaced by `Path.open()`
- scripts/lib/check_rabbitmq_queue.py:194:14: PTH123 `open()` should be replaced by `Path.open()`
+ scripts/lib/node_cache.py:15:14: PTH123 [*] `open()` should be replaced by `Path.open()`
... 559 additional changes omitted for project

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
PTH123 1684 0 0 1684 0

@chirizxc chirizxc marked this pull request as draft September 2, 2025 21:39
@chirizxc
Copy link
Contributor Author

chirizxc commented Sep 3, 2025

I'm not sure which tests should be included in the tests files, but i tested in this file:

The first line with #noqa so that they don't turn during the fix, the second line is needed to observe how the code is fixed, and the third line is what I expect to see after the fix, and then I compare lines 2 and 3

# ruff: noqa: SIM115, PLW1514, FBT003
import builtins
from pathlib import Path

_file = "file.txt"
_x = ("r+", -1)
r_plus = "r+"

builtins.open(file=_file)  # noqa: PTH123
builtins.open(file=_file)
Path(_file).open()

open(mode="wb", file=_file)  # noqa: PTH123
open(mode="wb", file=_file)
Path(_file).open(mode="wb")

open(mode="r+", buffering=-1, file=_file, encoding="utf-8")  # noqa: PTH123
open(mode="r+", buffering=-1, file=_file, encoding="utf-8")
Path(_file).open(mode="r+", buffering=-1, encoding="utf-8")

open(_file, "r+", -1, None, None, None)  # noqa: PTH123
open(_file, "r+", -1, None, None, None)
Path(_file).open("r+", -1, None, None, None)

open(_file, "r+", -1, None, None, None, closefd=True, opener=None)  # noqa: PTH123
open(_file, "r+", -1, None, None, None, closefd=True, opener=None)
Path(_file).open("r+", -1, None, None, None)

open(_file, mode="r+", buffering=-1, encoding=None, errors=None, newline=None)  # noqa: PTH123
open(_file, mode="r+", buffering=-1, encoding=None, errors=None, newline=None)
Path(_file).open(mode="r+", buffering=-1, encoding=None, errors=None, newline=None)


open(buffering=-      1, file=_file, encoding=         "utf-8")  # noqa: PTH123
open(buffering=-      1, file=_file, encoding=         "utf-8")
Path(_file).open(buffering=-1, encoding="utf-8")

open(_file, "r+", - 1, None, None, None, True, None)  # noqa: PTH123
open(_file, "r+", - 1, None, None, None, True, None)
Path(_file).open("r+", -1, None, None, None)

open(_file, "r+ ", -  1)  # noqa: PTH123
open(_file, "r+ ", -  1)
Path(_file).open("r+ ", -1)

open(_file, f"  {r_plus}      ", -  1)  # noqa: PTH123
open(_file, f"  {r_plus}      ", -  1)
Path(_file).open(f"  {r_plus}      ", -1)

# Only diagnostic
open()
open(_file, *_x)
open(_file, "r+", unknown=True)
open(_file, "r+", closefd=False)
open(_file, "r+", None, None, None, None, None, None, None)

@chirizxc chirizxc marked this pull request as ready for review September 3, 2025 12:58
@chirizxc chirizxc marked this pull request as draft September 5, 2025 16:12
@chirizxc chirizxc marked this pull request as ready for review September 6, 2025 10:09
@ntBre ntBre added fixes Related to suggested fixes for violations preview Related to preview mode features labels Sep 11, 2025
Copy link
Contributor

@ntBre ntBre left a comment

Choose a reason for hiding this comment

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

Thanks! I think you could add those tests to a new file called PTH123.py. It looks like there's some overlap with the test you added in import_from.py, so we could either add the additional file or just add more cases there?

This looks good to me overall, just a few minor suggestions.

@chirizxc
Copy link
Contributor Author

Copy link
Contributor

@ntBre ntBre left a comment

Choose a reason for hiding this comment

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

Thanks! Just two more minor things, but I think this looks good otherwise.

Copy link
Contributor

@ntBre ntBre left a comment

Choose a reason for hiding this comment

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

Thank you!

@ntBre ntBre merged commit bfb0902 into astral-sh:main Sep 17, 2025
35 checks passed
@chirizxc
Copy link
Contributor Author

I guess I forgot about that, thanks for the change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fixes Related to suggested fixes for violations preview Related to preview mode features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants