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

W1514 unspecified-encoding false positive when mode is specified using a variable and it can be 'b' (binary mode) #10201

Open
mitesh-raval opened this issue Jan 27, 2025 · 1 comment
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation

Comments

@mitesh-raval
Copy link

Bug description

@contextmanager
def open_file_seek_zero(some_str, mode):
    ...
    with open(file_name, mode) as f:        # <===   this line is reported for W1514
        f.seek(0)
        yield f

============ above function usage ============
def some_other_func:
    with open_file_seek_zero(some_str, "r+b") as f:
        ...
==============================================

Configuration

Command used

pylint --rc=.pylintrc file_ops.py (made up file name)

Pylint output

************* Module file_ops
file_ops.py:29:9: W1514: Using open without explicitly specifying an encoding (unspecified-encoding)

Expected behavior

When file opening mode is not clearly discernable, unspecified-encoding should not be reported.

If I disable it in rc, I won't catch genuine errors.

Pylint version

pylint 3.3.3
astroid 3.3.8
Python 3.10.5

OS / Environment

No response

Additional dependencies

@mitesh-raval mitesh-raval added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Jan 27, 2025
@Pierre-Sassoulas Pierre-Sassoulas added False Negative 🦋 No message is emitted but something is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Jan 28, 2025
@Pierre-Sassoulas
Copy link
Member

Thank you for opening the issue. I agree that when we don't know because we cannot infer we shouldn't raise a message.

@mbyrnepr2 mbyrnepr2 added False Positive 🦟 A message is emitted but nothing is wrong with the code and removed False Negative 🦋 No message is emitted but something is wrong with the code labels Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

No branches or pull requests

3 participants