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

Feature request: PLW1514 autofix #8883

Closed
Avasam opened this issue Nov 28, 2023 · 2 comments · Fixed by #8928
Closed

Feature request: PLW1514 autofix #8883

Avasam opened this issue Nov 28, 2023 · 2 comments · Fixed by #8928
Labels
fixes Related to suggested fixes for violations

Comments

@Avasam
Copy link

Avasam commented Nov 28, 2023

Can an autofix be created for the preview rule PLW1514 ? Even if it's "unsafe". Updating hundreds of instances manually is quite tedious.

In Python 3.10+ this would autofix to encoding="locale", in Python <=3.9 this would autofix to encoding=locale.getpreferredencoding(False) (see: https://peps.python.org/pep-0597/). Search & replacing those if I want a specific encoding is easier. An option to specify prefered encoding can also be set (which could even be re-used by a new rule that ensures consistent encoding is used with desired value, like "utf-8")

@Avasam Avasam changed the title PLW1514 autofix Feature request: PLW1514 autofix Nov 28, 2023
@charliermarsh charliermarsh added the fixes Related to suggested fixes for violations label Nov 28, 2023
@qdegraaf
Copy link
Contributor

While I'm working on the general utility mentioned in #8928 (comment), if anyone wants to do the autofix separately in the meantime, feel free to jump in.

charliermarsh pushed a commit that referenced this issue Dec 1, 2023
## Summary

- Adds `add_argument` similar to existing `remove_argument` utility to
safely add arguments to functions.
- Adds autofix for `PLW1514` as per specs requested in
#8883 as a test

## Test Plan

Checks on existing fixtures as well as additional test and fixture for
Python 3.9 and lower fix

## Issue Link

Closes: #8883
@Avasam
Copy link
Author

Avasam commented Dec 1, 2023

Thank you! Will give it a go next release.

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants