diff --git a/doc/whatsnew/fragments/10791.false_positive b/doc/whatsnew/fragments/10791.false_positive new file mode 100644 index 0000000000..6396916ccb --- /dev/null +++ b/doc/whatsnew/fragments/10791.false_positive @@ -0,0 +1,3 @@ +Avoid emitting `unspecified-encoding` (W1514) when `py-version` is 3.15+. + +Refs #10791 diff --git a/pylint/checkers/stdlib.py b/pylint/checkers/stdlib.py index 8a19480d7c..287a36e888 100644 --- a/pylint/checkers/stdlib.py +++ b/pylint/checkers/stdlib.py @@ -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", diff --git a/tests/functional/u/unspecified_encoding_py315.py b/tests/functional/u/unspecified_encoding_py315.py new file mode 100644 index 0000000000..83288f9b67 --- /dev/null +++ b/tests/functional/u/unspecified_encoding_py315.py @@ -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) diff --git a/tests/functional/u/unspecified_encoding_py315.rc b/tests/functional/u/unspecified_encoding_py315.rc new file mode 100644 index 0000000000..4a6b064da5 --- /dev/null +++ b/tests/functional/u/unspecified_encoding_py315.rc @@ -0,0 +1,6 @@ +[MAIN] +py-version=3.15 + +[Messages Control] +disable=all +enable=unspecified-encoding diff --git a/tests/functional/u/unspecified_encoding_py38.rc b/tests/functional/u/unspecified_encoding_py38.rc new file mode 100644 index 0000000000..a711c25d12 --- /dev/null +++ b/tests/functional/u/unspecified_encoding_py38.rc @@ -0,0 +1,2 @@ +[MAIN] +py-version=3.8 diff --git a/tests/testutils/data/m/minimal_messages_config.py b/tests/testutils/data/m/minimal_messages_config.py index ac0b70ec73..b883c3d759 100644 --- a/tests/testutils/data/m/minimal_messages_config.py +++ b/tests/testutils/data/m/minimal_messages_config.py @@ -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]