Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/10791.false_positive
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Avoid emitting `unspecified-encoding` (W1514) when `py-version` is 3.15+.

Refs #10791
1 change: 1 addition & 0 deletions pylint/checkers/stdlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@ class StdlibChecker(DeprecatedMixin, BaseChecker):
"It is better to specify an encoding when opening documents. "
"Using the system default implicitly can create problems on other operating systems. "
"See https://peps.python.org/pep-0597/",
{"maxversion": (3, 15)},
),
"W1515": (
"Leaving functions creating breakpoints in production code is not recommended",
Expand Down
18 changes: 18 additions & 0 deletions tests/functional/u/unspecified_encoding_py315.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""No warnings for using open() without specifying an encoding (Python 3.15+)."""

import io
from pathlib import Path

FILENAME = "foo.bar"

open(FILENAME)
open(FILENAME, encoding=None)
io.open(FILENAME)
io.open(FILENAME, encoding=None)

Path(FILENAME).open()
Path(FILENAME).open(encoding=None)
Path(FILENAME).read_text()
Path(FILENAME).read_text(encoding=None)
Path(FILENAME).write_text("string")
Path(FILENAME).write_text("string", encoding=None)
6 changes: 6 additions & 0 deletions tests/functional/u/unspecified_encoding_py315.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[MAIN]
py-version=3.15

[Messages Control]
disable=all
enable=unspecified-encoding
2 changes: 2 additions & 0 deletions tests/functional/u/unspecified_encoding_py38.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[MAIN]
py-version=3.8
3 changes: 2 additions & 1 deletion tests/testutils/data/m/minimal_messages_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
``test_minimal_messages_config_excluded_file``.
"""

f = open("foo.txt") # [consider-using-with, unspecified-encoding]
f = open("foo.txt") # [consider-using-with]
# -1:<3.15: [unspecified-encoding]

print("%d" % 1) # [consider-using-f-string]
Loading