Skip to content
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

[pylint] Detect pathlib.Path.open calls in unspecified-encoding (PLW1514) #11288

Merged
merged 7 commits into from
May 9, 2024

Conversation

augustelalande
Copy link
Contributor

Summary

Resolves #11263

Detect pathlib.Path.open calls which do not specify a file encoding.

Test Plan

Test cases added to fixture.

@augustelalande
Copy link
Contributor Author

augustelalande commented May 5, 2024

I was not able to detect violations of the form

x = Path("foo.txt")
x.open()

I don't know if this is currently doable.

Copy link
Contributor

github-actions bot commented May 5, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+76 -0 violations, +0 -0 fixes in 7 projects; 37 projects unchanged)

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

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

+ .github/scripts/authors_in_cff.py:35:10: PLW1514 `pathlib.Path(...).open` in text mode without explicit `encoding` argument

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

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

+ airflow/providers/alibaba/cloud/log/oss_task_handler.py:98:19: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ airflow/providers/amazon/aws/log/s3_task_handler.py:106:19: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ airflow/providers/smtp/notifications/smtp.py:105:24: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ airflow/providers/smtp/notifications/smtp.py:112:33: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ airflow/providers/smtp/notifications/smtp.py:119:33: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ airflow/providers/trino/hooks/trino.py:118:25: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ airflow/utils/code_utils.py:65:18: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ dev/breeze/src/airflow_breeze/commands/setup_commands.py:404:13: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ dev/breeze/src/airflow_breeze/commands/setup_commands.py:414:5: PLW1514 `pathlib.Path(...).write_text` without explicit `encoding` argument
+ dev/breeze/src/airflow_breeze/global_constants.py:386:6: PLW1514 `pathlib.Path(...).open` in text mode without explicit `encoding` argument
+ dev/breeze/src/airflow_breeze/utils/md5_build_check.py:50:36: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ docker_tests/test_examples_of_prod_image_building.py:78:15: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ docs/exts/operators_and_hooks_ref.py:213:52: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ docs/exts/operators_and_hooks_ref.py:318:52: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ docs/exts/providers_extensions.py:111:48: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ scripts/ci/pre_commit/check_aiobotocore_optional.py:35:48: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ tests/providers/amazon/aws/hooks/test_eks.py:1251:37: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ tests/providers/google/common/hooks/test_base_google.py:226:20: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ tests/system/providers/google/cloud/gcs/resources/transform_timespan.py:34:1: PLW1514 `pathlib.Path(...).write_text` without explicit `encoding` argument
+ tests/system/providers/weaviate/example_weaviate_cohere.py:59:26: PLW1514 `pathlib.Path(...).open` in text mode without explicit `encoding` argument
... 11 additional changes omitted for project

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

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

+ tests/integration/buildcmd/test_build_samconfig.py:129:42: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ tests/integration/buildcmd/test_build_samconfig.py:131:31: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ tests/integration/buildcmd/test_build_samconfig.py:88:42: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ tests/integration/buildcmd/test_build_samconfig.py:89:27: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ tests/integration/init/test_init_command.py:822:9: PLW1514 `pathlib.Path(...).write_text` without explicit `encoding` argument
+ tests/integration/init/test_init_command.py:837:26: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ tests/unit/commands/pipeline/init/test_initeractive_init_flow.py:606:13: PLW1514 `pathlib.Path(...).write_text` without explicit `encoding` argument
+ tests/unit/commands/pipeline/init/test_initeractive_init_flow.py:617:13: PLW1514 `pathlib.Path(...).write_text` without explicit `encoding` argument
+ tests/unit/commands/pipeline/init/test_initeractive_init_flow.py:629:13: PLW1514 `pathlib.Path(...).write_text` without explicit `encoding` argument
+ tests/unit/commands/samconfig/test_samconfig.py:1032:9: PLW1514 `pathlib.Path(...).write_text` without explicit `encoding` argument
+ tests/unit/commands/samconfig/test_samconfig.py:1033:9: PLW1514 `pathlib.Path(...).write_text` without explicit `encoding` argument
+ tests/unit/commands/samconfig/test_samconfig.py:1070:23: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ tests/unit/commands/samconfig/test_samconfig.py:1175:23: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ tests/unit/commands/samconfig/test_samconfig.py:1253:23: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ tests/unit/commands/samconfig/test_samconfig.py:130:23: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ tests/unit/commands/samconfig/test_samconfig.py:190:23: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ tests/unit/commands/samconfig/test_samconfig.py:247:23: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ tests/unit/commands/samconfig/test_samconfig.py:303:23: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ tests/unit/commands/samconfig/test_samconfig.py:30:9: PLW1514 `pathlib.Path(...).write_text` without explicit `encoding` argument
+ tests/unit/commands/samconfig/test_samconfig.py:31:9: PLW1514 `pathlib.Path(...).write_text` without explicit `encoding` argument
+ tests/unit/commands/samconfig/test_samconfig.py:365:23: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ tests/unit/commands/samconfig/test_samconfig.py:429:23: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ tests/unit/commands/samconfig/test_samconfig.py:496:23: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
... 12 additional changes omitted for project

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

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

+ securedrop/source_user.py:234:21: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ securedrop/source_user.py:235:26: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument

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

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

+ ibis/backends/duckdb/tests/test_register.py:280:13: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument

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

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

+ bin/update_how_it_works_image.py:26:16: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ bin/update_how_it_works_image.py:28:17: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ bin/update_how_it_works_image.py:29:17: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ bin/update_how_it_works_image.py:30:17: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument

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

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

+ tests/test_custom_modules.py:23:16: PLW1514 `pathlib.Path(...).read_text` without explicit `encoding` argument
+ tests/test_dynamic_metadata.py:267:10: PLW1514 `pathlib.Path(...).open` in text mode without explicit `encoding` argument

Changes by rule (1 rules affected)

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

@dhruvmanila dhruvmanila added the rule Implementing or modifying a lint rule label May 6, 2024
@augustelalande
Copy link
Contributor Author

@dhruvmanila Done as requested.

I was not able to detect violations of the form

x = Path("foo.txt")
x.open()

I don't know if this is currently doable.

Any comment on this

@dhruvmanila
Copy link
Member

@dhruvmanila Done as requested.

I was not able to detect violations of the form

x = Path("foo.txt")
x.open()

I don't know if this is currently doable.

Any comment on this

I think it's fine to not detect this now as this would fall under the bucket of type-inference.

Copy link
Member

@dhruvmanila dhruvmanila 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 for working on this!

I've added some additional test cases and actually used QualifiedName for the Regular variant. This is to re-use the Display implementation on QualifiedName.

@dhruvmanila
Copy link
Member

The ecosystem changes looks correct.

@dhruvmanila dhruvmanila added the preview Related to preview mode features label May 9, 2024
@dhruvmanila dhruvmanila enabled auto-merge (squash) May 9, 2024 11:13
@dhruvmanila dhruvmanila disabled auto-merge May 9, 2024 11:17
@dhruvmanila
Copy link
Member

After a good amount of discussion, I've decided to name it Callee ;)

Feel free to disagree with any of the changes made by me.

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.

PLW1514 does not check for uses of pathlib.Path.open() without an explicit encoding argument.
2 participants