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

UP015 RedundantOpenModes false positive with gzip.open #1026

Closed
andersk opened this issue Dec 4, 2022 · 0 comments · Fixed by #1027
Closed

UP015 RedundantOpenModes false positive with gzip.open #1026

andersk opened this issue Dec 4, 2022 · 0 comments · Fixed by #1027

Comments

@andersk
Copy link
Contributor

andersk commented Dec 4, 2022

Ruff’s fix for UP015 (#843) incorrectly changes the behavior of gzip.open(…, "rt"). This mode should not be flagged as redundant because the default for gzip.open is "rb".

$ cat test.py
import gzip
with gzip.open("test.gz", "rt") as f:
    print(f.read())

$ echo 'Hello, world!' | gzip > test.gz

$ python test.py
Hello, world!

$ ruff --select=UP test.py
Found 1 error(s).
test.py:2:6: UP015 Unnecessary open mode parameters
1 potentially fixable with the --fix option.

$ ruff --select=UP --fix test.py
Found 0 error(s) (1 fixed).

$ cat test.py
import gzip
with gzip.open("test.gz") as f:
    print(f.read())

$ python test.py
b'Hello, world!\n'

Cc @andribergs

andersk added a commit to andersk/ruff that referenced this issue Dec 4, 2022
The more accurate match_module_member should be preferred.

Fixes astral-sh#1026.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant