Skip to content

Conversation

danparizher
Copy link
Contributor

Summary

Fixes #19294

Copy link
Contributor

github-actions bot commented Jul 13, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+206 -0 violations, +0 -0 fixes in 12 projects; 43 projects unchanged)

PlasmaPy/PlasmaPy (+7 -0 violations, +0 -0 fixes)

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

+ .github/scripts/citation_updater.py:34:10: PLW1514 `pathlib.Path(...).open` in text mode without explicit `encoding` argument
+ .github/scripts/citation_updater.py:41:10: PLW1514 `pathlib.Path(...).open` in text mode without explicit `encoding` argument
+ .github/scripts/citation_updater.py:45:25: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ .github/scripts/citation_updater.py:64:10: PLW1514 `pathlib.Path(...).open` in text mode without explicit `encoding` argument
+ noxfile.py:119:10: PLW1514 `pathlib.Path(...).open` in text mode without explicit `encoding` argument
+ src/plasmapy/utils/calculator/main_interface.py:163:10: PLW1514 `pathlib.Path(...).open` in text mode without explicit `encoding` argument
+ tests/utils/data/test_downloader.py:188:10: PLW1514 `pathlib.Path(...).open` in text mode without explicit `encoding` argument

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

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

+ airflow-core/src/airflow/dag_processing/bundles/base.py:390:13: PLW1514 `pathlib.Path(...).write_text` without explicit `encoding` argument
+ airflow-core/src/airflow/utils/code_utils.py:62:18: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ airflow-core/tests/unit/dags/test_parsing_context.py:44:9: PLW1514 `pathlib.Path(...).write_text` without explicit `encoding` argument
+ dev/assign_cherry_picked_prs_with_milestone.py:382:13: PLW1514 `pathlib.Path(...).write_text` without explicit `encoding` argument
+ dev/breeze/src/airflow_breeze/commands/release_management_commands.py:2904:20: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ dev/breeze/src/airflow_breeze/commands/release_management_commands.py:2922:26: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ dev/breeze/src/airflow_breeze/commands/release_management_commands.py:2934:13: PLW1514 `pathlib.Path(...).write_text` without explicit `encoding` argument
+ dev/breeze/src/airflow_breeze/commands/setup_commands.py:412:30: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ dev/breeze/src/airflow_breeze/commands/setup_commands.py:427:20: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ dev/breeze/src/airflow_breeze/commands/setup_commands.py:431:9: PLW1514 `pathlib.Path(...).write_text` without explicit `encoding` argument
+ dev/breeze/src/airflow_breeze/commands/setup_commands.py:716:12: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ dev/breeze/src/airflow_breeze/commands/setup_commands.py:729:5: PLW1514 `pathlib.Path(...).write_text` without explicit `encoding` argument
+ dev/breeze/src/airflow_breeze/prepare_providers/provider_documentation.py:1284:25: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ dev/breeze/src/airflow_breeze/prepare_providers/provider_documentation.py:1290:5: PLW1514 `pathlib.Path(...).write_text` without explicit `encoding` argument
+ dev/breeze/src/airflow_breeze/prepare_providers/provider_documentation.py:676:13: PLW1514 `pathlib.Path(...).write_text` without explicit `encoding` argument
+ dev/breeze/src/airflow_breeze/utils/add_back_references.py:52:10: PLW1514 `pathlib.Path(...).open` in text mode without explicit `encoding` argument
+ dev/breeze/src/airflow_breeze/utils/add_back_references.py:76:9: PLW1514 `pathlib.Path(...).write_text` without explicit `encoding` argument
+ dev/breeze/src/airflow_breeze/utils/cache.py:66:9: PLW1514 `pathlib.Path(...).write_text` without explicit `encoding` argument
+ dev/breeze/src/airflow_breeze/utils/constraints_version_check.py:299:13: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ dev/breeze/src/airflow_breeze/utils/constraints_version_check.py:313:5: PLW1514 `pathlib.Path(...).write_text` without explicit `encoding` argument
+ dev/breeze/src/airflow_breeze/utils/constraints_version_check.py:333:28: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
... 68 additional changes omitted for project

aws/aws-sam-cli (+53 -0 violations, +0 -0 fixes)

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

+ samcli/lib/config/file_manager.py:105:19: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ samcli/lib/config/file_manager.py:136:9: PLW1514 `pathlib.Path(...).write_text` without explicit `encoding` argument
+ samcli/lib/config/file_manager.py:191:50: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ samcli/lib/config/file_manager.py:289:36: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ samcli/lib/config/file_manager.py:312:14: PLW1514 `pathlib.Path(...).open` in text mode without explicit `encoding` argument
+ samcli/lib/utils/configuration.py:12:21: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ tests/functional/commands/cli/test_global_config.py:106:32: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ tests/functional/commands/cli/test_global_config.py:119:32: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ tests/functional/commands/cli/test_global_config.py:132:32: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ tests/functional/commands/cli/test_global_config.py:186:32: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ tests/functional/commands/cli/test_global_config.py:200:32: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ tests/functional/commands/cli/test_global_config.py:216:32: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
... 41 additional changes omitted for project

freedomofpress/securedrop (+11 -0 violations, +0 -0 fixes)

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

+ securedrop/debian/app-code/usr/bin/securedrop-set-redis-auth.py:24:16: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ securedrop/debian/app-code/usr/bin/securedrop-set-redis-auth.py:38:17: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ securedrop/debian/app-code/usr/bin/securedrop-set-redis-auth.py:47:9: PLW1514 `pathlib.Path(...).write_text` without explicit `encoding` argument
+ securedrop/debian/app-code/usr/bin/securedrop-set-redis-auth.py:51:5: PLW1514 `pathlib.Path(...).write_text` without explicit `encoding` argument
+ securedrop/debian/app-code/usr/bin/securedrop-set-redis-auth.py:58:16: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ securedrop/debian/app-code/usr/bin/securedrop-set-redis-auth.py:73:13: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ securedrop/debian/app-code/usr/bin/securedrop-set-redis-auth.py:78:5: PLW1514 `pathlib.Path(...).write_text` without explicit `encoding` argument
+ securedrop/server_os.py:41:31: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ securedrop/tests/test_i18n.py:70:18: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ securedrop/tests/test_i18n.py:82:5: PLW1514 `pathlib.Path(...).write_text` without explicit `encoding` argument
... 1 additional changes omitted for project

ibis-project/ibis (+4 -0 violations, +0 -0 fixes)

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

+ ci/make_geography_db.py:64:13: PLW1514 `pathlib.Path(...).write_text` without explicit `encoding` argument
+ ci/release/verify_release.py:46:12: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ ibis/backends/snowflake/tests/conftest.py:40:23: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ ibis/examples/gen_registry.py:45:39: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument

langchain-ai/langchain (+8 -0 violations, +0 -0 fixes)

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

+ libs/core/langchain_core/language_models/llms.py:1432:18: PLW1514 `pathlib.Path(...).open` in text mode without explicit `encoding` argument
+ libs/core/langchain_core/language_models/llms.py:1435:18: PLW1514 `pathlib.Path(...).open` in text mode without explicit `encoding` argument
+ libs/core/langchain_core/prompts/base.py:384:18: PLW1514 `pathlib.Path(...).open` in text mode without explicit `encoding` argument
+ libs/core/langchain_core/prompts/base.py:387:18: PLW1514 `pathlib.Path(...).open` in text mode without explicit `encoding` argument
+ libs/core/langchain_core/prompts/loading.py:56:24: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ libs/core/langchain_core/prompts/loading.py:70:14: PLW1514 `pathlib.Path(...).open` in text mode without explicit `encoding` argument
+ libs/core/langchain_core/vectorstores/in_memory.py:600:14: PLW1514 `pathlib.Path(...).open` in text mode without explicit `encoding` argument
+ libs/core/langchain_core/vectorstores/in_memory.py:614:14: PLW1514 `pathlib.Path(...).open` in text mode without explicit `encoding` argument

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

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

+ src/latch_cli/main.py:1258:26: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ src/latch_cli/nextflow/config.py:49:31: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ src/latch_cli/nextflow/parse_schema.py:377:38: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ src/latch_cli/nextflow/parse_schema.py:393:38: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ src/latch_cli/nextflow/workflow.py:472:5: PLW1514 `pathlib.Path(...).write_text` without explicit `encoding` argument
+ src/latch_cli/services/init/init.py:138:13: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ src/latch_cli/services/init/init.py:144:5: PLW1514 `pathlib.Path(...).write_text` without explicit `encoding` argument
+ src/latch_cli/snakemake/config/parser.py:47:41: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument

... Truncated remaining completed project reports due to GitHub comment length restrictions

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
PLW1514 206 206 0 0 0

@MichaReiser MichaReiser added rule Implementing or modifying a lint rule preview Related to preview mode features labels Jul 14, 2025
@MichaReiser MichaReiser requested a review from ntBre July 14, 2025 09:14
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.

I think we can reuse some existing type inference code for this.

return Some(Callee::Pathlib(attr));
}
// Indirect: x.open() where x = Path(...)
else if let Expr::Name(name) = value.as_ref() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this would be a good use of our typing module:

/// Test whether the given binding can be considered a `pathlib.PurePath`
/// or an instance of a subclass thereof.
pub fn is_pathlib_path(binding: &Binding, semantic: &SemanticModel) -> bool {
check_type::<PathlibPathChecker>(binding, semantic)
}

It looks like we already have one for Path. I think this will also allow us to cover the annotated function argument case from the issue, whereas I don't think this implementation would.

def format_file(file: Path):
    with file.open() as f:
        contents = f.read()

It might be good to add this as a test case if it does work.

@danparizher danparizher requested a review from ntBre July 14, 2025 20:38
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.

Looks good, just one suggestion to delete a redundant section of code.

@ntBre
Copy link
Contributor

ntBre commented Jul 16, 2025

I spot-checked the ecosystem changes, and this looks like a really handy change! We can use that to make sure my suggestion doesn't break anything too (currently +206 violations).

@danparizher
Copy link
Contributor Author

Looks good to go! 🙂

@ntBre
Copy link
Contributor

ntBre commented Jul 16, 2025

Excellent, thank you!

@ntBre ntBre merged commit b2501b4 into astral-sh:main Jul 16, 2025
35 checks passed
@danparizher danparizher deleted the fix-19294 branch July 16, 2025 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

[pylint] False negative on indirect pathlib.Paths (PLW1514)
3 participants