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

Getting unspecified-encoding when using Path().open('rb') #5018

Closed
ecs-jnguyen opened this issue Sep 16, 2021 · 2 comments
Closed

Getting unspecified-encoding when using Path().open('rb') #5018

ecs-jnguyen opened this issue Sep 16, 2021 · 2 comments
Labels
Bug 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code
Milestone

Comments

@ecs-jnguyen
Copy link

ecs-jnguyen commented Sep 16, 2021

Bug description

I am running into the error unspecified-encoding when using Path().open("rb")

Example python code:

file.py

"""Module docstring."""
from pathlib import Path

hello_txt = Path("hello.txt")

# file.py:7:5: W1514: Using open without explicitly specifying an encoding (unspecified-encoding)
with hello_txt.open("rb") as stream:
    print(stream.read().decode())

hello.txt

hello there

Configuration

No response

Command used

pylint file.py

Pylint output

************* Module file
file.py:7:5: W1514: Using open without explicitly specifying an encoding (unspecified-encoding)

------------------------------------------------------------------
Your code has been rated at 7.50/10 (previous run: 7.50/10, +0.00)

Expected behavior

We should not see the unspecified-encoding error because we are opening the file in binary mode. When I try to open the file with with hello_txt.open("rb", encoding="utf-8") as stream: I will get the following output

Traceback (most recent call last):
  File ".../file.py", line 7, in <module>
    with hello_txt.open("rb", encoding="utf-8") as stream:
  File ".../3.9.6/lib/python3.9/pathlib.py", line 1242, in open
    return io.open(self, mode, buffering, encoding, errors, newline,
ValueError: binary mode doesn't take an encoding argument

Pylint version

pylint 2.11.0
astroid 2.8.0
Python 3.9.6 (default, Sep  1 2021, 13:57:59) 
[Clang 12.0.0 (clang-1200.0.32.28)]

OS / Environment

Mac and iterm2

Additional dependencies

astroid==2.8.0
isort==5.9.3
lazy-object-proxy==1.6.0
mccabe==0.6.1
platformdirs==2.3.0
pylint==2.11.0
toml==0.10.2
typing-extensions==3.10.0.2
wrapt==1.12.1

@ecs-jnguyen ecs-jnguyen added Bug 🪲 Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Sep 16, 2021
@Pierre-Sassoulas
Copy link
Member

Thank you for opening the issue, This is a duplicate of #5017 which was open in parallel.

@Pierre-Sassoulas Pierre-Sassoulas added False Positive 🦟 A message is emitted but nothing is wrong with the code and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Sep 16, 2021
@ecs-jnguyen
Copy link
Author

ah i was beat by less than 15 minutes haha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code
Projects
None yet
Development

No branches or pull requests

2 participants