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

unspecified-encoding when using Path().read_text() without encoding keyword argument #5029

Closed
GeZZu opened this issue Sep 17, 2021 · 3 comments · Fixed by #5033
Closed

unspecified-encoding when using Path().read_text() without encoding keyword argument #5029

GeZZu opened this issue Sep 17, 2021 · 3 comments · Fixed by #5033
Labels
Bug 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code
Milestone

Comments

@GeZZu
Copy link

GeZZu commented Sep 17, 2021

Bug description

I will get unspecified-encoding even when I provide the encoding to Path().read_text() funciton.
For example Path().read_text("UTF-8").

I'll get rid of the warning by giving keyword argument Path().read_text(encoding="UTF-8")

Configuration

No response

Command used

pylint test.py -e unspecified-encoding

Pylint output

W1514: Using open without explicitly specifying an encoding (unspecified-encoding)

Expected behavior

No warnings are given when providing encoding without keyword.

Pylint version

pylint 2.11.1
astroid 2.8.0
Python 3.9.6 (tags/v3.9.6:db3ff76, Jun 28 2021, 15:26:21) [MSC v.1929 64 bit (AMD64)]

OS / Environment

No response

Additional dependencies

No response

@GeZZu GeZZu added Bug 🪲 Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Sep 17, 2021
@DanielNoord
Copy link
Collaborator

Based on the code in pathlib I don't think you are actually supplying an encoding, see:

    def write_text(self, data, encoding=None, errors=None):
        """
        Open the file in text mode, write to it, and close the file.
        """
        if not isinstance(data, str):
            raise TypeError('data must be str, not %s' %
                            data.__class__.__name__)
        with self.open(mode='w', encoding=encoding, errors=errors) as f:
            return f.write(data)

If I read the code correctly, you are passing "UTF-8" as data instead of encoding.

@Pierre-Sassoulas
Copy link
Member

Pierre-Sassoulas commented Sep 17, 2021

I think it's for read_text and not write_text:

    def read_text(self, encoding=None, errors=None):
        """
        Open the file in text mode, read it, and close the file.
        """
        with self.open(mode='r', encoding=encoding, errors=errors) as f:
            return f.read()

@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 17, 2021
@Pierre-Sassoulas Pierre-Sassoulas changed the title unspecified-encoding when using Path().read_text() without encoding keyword argument unspecified-encoding when using Path().read_text() without encoding keyword argument Sep 17, 2021
@DanielNoord
Copy link
Collaborator

My bad! Working on a fix now!

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

Successfully merging a pull request may close this issue.

3 participants