Skip to content

Commit 7b73bfd

Browse files
MehrazRummanDanielNoord
authored andcommitted
Disable unspecified-encoding for py-version above Python 3.15 (#10800)
(cherry picked from commit de75d30)
1 parent 4cc98be commit 7b73bfd

File tree

6 files changed

+32
-1
lines changed

6 files changed

+32
-1
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Avoid emitting `unspecified-encoding` (W1514) when `py-version` is 3.15+.
2+
3+
Refs #10791

pylint/checkers/stdlib.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@ class StdlibChecker(DeprecatedMixin, BaseChecker):
580580
"It is better to specify an encoding when opening documents. "
581581
"Using the system default implicitly can create problems on other operating systems. "
582582
"See https://peps.python.org/pep-0597/",
583+
{"maxversion": (3, 15)},
583584
),
584585
"W1515": (
585586
"Leaving functions creating breakpoints in production code is not recommended",
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""No warnings for using open() without specifying an encoding (Python 3.15+)."""
2+
3+
import io
4+
from pathlib import Path
5+
6+
FILENAME = "foo.bar"
7+
8+
open(FILENAME)
9+
open(FILENAME, encoding=None)
10+
io.open(FILENAME)
11+
io.open(FILENAME, encoding=None)
12+
13+
Path(FILENAME).open()
14+
Path(FILENAME).open(encoding=None)
15+
Path(FILENAME).read_text()
16+
Path(FILENAME).read_text(encoding=None)
17+
Path(FILENAME).write_text("string")
18+
Path(FILENAME).write_text("string", encoding=None)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[MAIN]
2+
py-version=3.15
3+
4+
[Messages Control]
5+
disable=all
6+
enable=unspecified-encoding
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[MAIN]
2+
py-version=3.8

tests/testutils/data/m/minimal_messages_config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
``test_minimal_messages_config_excluded_file``.
66
"""
77

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

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

0 commit comments

Comments
 (0)