---
source: crates/ruff_linter/src/rules/pylint/mod.rs
---
PLW1514 [*] `open` in text mode without explicit `encoding` argument
  --> unspecified_encoding.py:8:1
   |
 7 | # Errors.
 8 | open("test.txt")
   | ^^^^
 9 | io.TextIOWrapper(io.FileIO("test.txt"))
10 | hugo.TextIOWrapper(hugo.FileIO("test.txt"))
   |
help: Add explicit `encoding` argument
  |
7 | # Errors.
  - open("test.txt")
8 + open("test.txt", encoding="utf-8")
9 | io.TextIOWrapper(io.FileIO("test.txt"))
  |
note: This is an unsafe fix and may change runtime behavior

PLW1514 [*] `io.TextIOWrapper` without explicit `encoding` argument
  --> unspecified_encoding.py:9:1
   |
 7 | # Errors.
 8 | open("test.txt")
 9 | io.TextIOWrapper(io.FileIO("test.txt"))
   | ^^^^^^^^^^^^^^^^
10 | hugo.TextIOWrapper(hugo.FileIO("test.txt"))
11 | tempfile.NamedTemporaryFile("w")
   |
help: Add explicit `encoding` argument
   |
8  | open("test.txt")
   - io.TextIOWrapper(io.FileIO("test.txt"))
9  + io.TextIOWrapper(io.FileIO("test.txt"), encoding="utf-8")
10 | hugo.TextIOWrapper(hugo.FileIO("test.txt"))
   |
note: This is an unsafe fix and may change runtime behavior

PLW1514 [*] `io.TextIOWrapper` without explicit `encoding` argument
  --> unspecified_encoding.py:10:1
   |
 8 | open("test.txt")
 9 | io.TextIOWrapper(io.FileIO("test.txt"))
10 | hugo.TextIOWrapper(hugo.FileIO("test.txt"))
   | ^^^^^^^^^^^^^^^^^^
11 | tempfile.NamedTemporaryFile("w")
12 | tempfile.TemporaryFile("w")
   |
help: Add explicit `encoding` argument
   |
9  | io.TextIOWrapper(io.FileIO("test.txt"))
   - hugo.TextIOWrapper(hugo.FileIO("test.txt"))
10 + hugo.TextIOWrapper(hugo.FileIO("test.txt"), encoding="utf-8")
11 | tempfile.NamedTemporaryFile("w")
   |
note: This is an unsafe fix and may change runtime behavior

PLW1514 [*] `tempfile.NamedTemporaryFile` in text mode without explicit `encoding` argument
  --> unspecified_encoding.py:11:1
   |
 9 | io.TextIOWrapper(io.FileIO("test.txt"))
10 | hugo.TextIOWrapper(hugo.FileIO("test.txt"))
11 | tempfile.NamedTemporaryFile("w")
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
12 | tempfile.TemporaryFile("w")
13 | codecs.open("test.txt")
   |
help: Add explicit `encoding` argument
   |
10 | hugo.TextIOWrapper(hugo.FileIO("test.txt"))
   - tempfile.NamedTemporaryFile("w")
11 + tempfile.NamedTemporaryFile("w", encoding="utf-8")
12 | tempfile.TemporaryFile("w")
   |
note: This is an unsafe fix and may change runtime behavior

PLW1514 [*] `tempfile.TemporaryFile` in text mode without explicit `encoding` argument
  --> unspecified_encoding.py:12:1
   |
10 | hugo.TextIOWrapper(hugo.FileIO("test.txt"))
11 | tempfile.NamedTemporaryFile("w")
12 | tempfile.TemporaryFile("w")
   | ^^^^^^^^^^^^^^^^^^^^^^
13 | codecs.open("test.txt")
14 | tempfile.SpooledTemporaryFile(0, "w")
   |
help: Add explicit `encoding` argument
   |
11 | tempfile.NamedTemporaryFile("w")
   - tempfile.TemporaryFile("w")
12 + tempfile.TemporaryFile("w", encoding="utf-8")
13 | codecs.open("test.txt")
   |
note: This is an unsafe fix and may change runtime behavior

PLW1514 [*] `codecs.open` in text mode without explicit `encoding` argument
  --> unspecified_encoding.py:13:1
   |
11 | tempfile.NamedTemporaryFile("w")
12 | tempfile.TemporaryFile("w")
13 | codecs.open("test.txt")
   | ^^^^^^^^^^^
14 | tempfile.SpooledTemporaryFile(0, "w")
   |
help: Add explicit `encoding` argument
   |
12 | tempfile.TemporaryFile("w")
   - codecs.open("test.txt")
13 + codecs.open("test.txt", encoding="utf-8")
14 | tempfile.SpooledTemporaryFile(0, "w")
   |
note: This is an unsafe fix and may change runtime behavior

PLW1514 [*] `tempfile.SpooledTemporaryFile` in text mode without explicit `encoding` argument
  --> unspecified_encoding.py:14:1
   |
12 | tempfile.TemporaryFile("w")
13 | codecs.open("test.txt")
14 | tempfile.SpooledTemporaryFile(0, "w")
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15 |
16 | # Non-errors.
   |
help: Add explicit `encoding` argument
   |
13 | codecs.open("test.txt")
   - tempfile.SpooledTemporaryFile(0, "w")
14 + tempfile.SpooledTemporaryFile(0, "w", encoding="utf-8")
15 |
   |
note: This is an unsafe fix and may change runtime behavior

PLW1514 [*] `open` in text mode without explicit `encoding` argument
  --> unspecified_encoding.py:46:1
   |
44 | tempfile.SpooledTemporaryFile(0, )
45 |
46 | open("test.txt",)
   | ^^^^
47 | open()
48 | open(
   |
help: Add explicit `encoding` argument
   |
45 |
   - open("test.txt",)
46 + open("test.txt", encoding="utf-8",)
47 | open()
   |
note: This is an unsafe fix and may change runtime behavior

PLW1514 [*] `open` in text mode without explicit `encoding` argument
  --> unspecified_encoding.py:47:1
   |
46 | open("test.txt",)
47 | open()
   | ^^^^
48 | open(
49 |     "test.txt",  # comment
   |
help: Add explicit `encoding` argument
   |
46 | open("test.txt",)
   - open()
47 + open(encoding="utf-8")
48 | open(
   |
note: This is an unsafe fix and may change runtime behavior

PLW1514 [*] `open` in text mode without explicit `encoding` argument
  --> unspecified_encoding.py:48:1
   |
46 | open("test.txt",)
47 | open()
48 | open(
   | ^^^^
49 |     "test.txt",  # comment
50 | )
   |
help: Add explicit `encoding` argument
   |
48 | open(
   -     "test.txt",  # comment
49 +     "test.txt", encoding="utf-8",  # comment
50 | )
   |
note: This is an unsafe fix and may change runtime behavior

PLW1514 [*] `open` in text mode without explicit `encoding` argument
  --> unspecified_encoding.py:51:1
   |
49 |     "test.txt",  # comment
50 | )
51 | open(
   | ^^^^
52 |     "test.txt",
53 |     # comment
   |
help: Add explicit `encoding` argument
   |
51 | open(
   -     "test.txt",
52 +     "test.txt", encoding="utf-8",
53 |     # comment
   |
note: This is an unsafe fix and may change runtime behavior

PLW1514 [*] `open` in text mode without explicit `encoding` argument
  --> unspecified_encoding.py:55:1
   |
53 |     # comment
54 | )
55 | open(("test.txt"),)
   | ^^^^
56 | open(
57 |     ("test.txt"),  # comment
   |
help: Add explicit `encoding` argument
   |
54 | )
   - open(("test.txt"),)
55 + open(("test.txt"), encoding="utf-8",)
56 | open(
   |
note: This is an unsafe fix and may change runtime behavior

PLW1514 [*] `open` in text mode without explicit `encoding` argument
  --> unspecified_encoding.py:56:1
   |
54 | )
55 | open(("test.txt"),)
56 | open(
   | ^^^^
57 |     ("test.txt"),  # comment
58 | )
   |
help: Add explicit `encoding` argument
   |
56 | open(
   -     ("test.txt"),  # comment
57 +     ("test.txt"), encoding="utf-8",  # comment
58 | )
   |
note: This is an unsafe fix and may change runtime behavior

PLW1514 [*] `open` in text mode without explicit `encoding` argument
  --> unspecified_encoding.py:59:1
   |
57 |     ("test.txt"),  # comment
58 | )
59 | open(
   | ^^^^
60 |     ("test.txt"),
61 |     # comment
   |
help: Add explicit `encoding` argument
   |
59 | open(
   -     ("test.txt"),
60 +     ("test.txt"), encoding="utf-8",
61 |     # comment
   |
note: This is an unsafe fix and may change runtime behavior

PLW1514 [*] `open` in text mode without explicit `encoding` argument
  --> unspecified_encoding.py:64:1
   |
62 | )
63 |
64 | open((("test.txt")),)
   | ^^^^
65 | open(
66 |     (("test.txt")),  # comment
   |
help: Add explicit `encoding` argument
   |
63 |
   - open((("test.txt")),)
64 + open((("test.txt")), encoding="utf-8",)
65 | open(
   |
note: This is an unsafe fix and may change runtime behavior

PLW1514 [*] `open` in text mode without explicit `encoding` argument
  --> unspecified_encoding.py:65:1
   |
64 | open((("test.txt")),)
65 | open(
   | ^^^^
66 |     (("test.txt")),  # comment
67 | )
   |
help: Add explicit `encoding` argument
   |
65 | open(
   -     (("test.txt")),  # comment
66 +     (("test.txt")), encoding="utf-8",  # comment
67 | )
   |
note: This is an unsafe fix and may change runtime behavior

PLW1514 [*] `open` in text mode without explicit `encoding` argument
  --> unspecified_encoding.py:68:1
   |
66 |     (("test.txt")),  # comment
67 | )
68 | open(
   | ^^^^
69 |     (("test.txt")),
70 |     # comment
   |
help: Add explicit `encoding` argument
   |
68 | open(
   -     (("test.txt")),
69 +     (("test.txt")), encoding="utf-8",
70 |     # comment
   |
note: This is an unsafe fix and may change runtime behavior

PLW1514 [*] `pathlib.Path(...).open` in text mode without explicit `encoding` argument
  --> unspecified_encoding.py:77:1
   |
76 | # Errors.
77 | Path("foo.txt").open()
   | ^^^^^^^^^^^^^^^^^^^^
78 | Path("foo.txt").open("w")
79 | text = Path("foo.txt").read_text()
   |
help: Add explicit `encoding` argument
   |
76 | # Errors.
   - Path("foo.txt").open()
77 + Path("foo.txt").open(encoding="utf-8")
78 | Path("foo.txt").open("w")
   |
note: This is an unsafe fix and may change runtime behavior

PLW1514 [*] `pathlib.Path(...).open` in text mode without explicit `encoding` argument
  --> unspecified_encoding.py:78:1
   |
76 | # Errors.
77 | Path("foo.txt").open()
78 | Path("foo.txt").open("w")
   | ^^^^^^^^^^^^^^^^^^^^
79 | text = Path("foo.txt").read_text()
80 | Path("foo.txt").write_text(text)
   |
help: Add explicit `encoding` argument
   |
77 | Path("foo.txt").open()
   - Path("foo.txt").open("w")
78 + Path("foo.txt").open("w", encoding="utf-8")
79 | text = Path("foo.txt").read_text()
   |
note: This is an unsafe fix and may change runtime behavior

PLW1514 [*] `pathlib.Path(...).read_text` without explicit `encoding` argument
  --> unspecified_encoding.py:79:8
   |
77 | Path("foo.txt").open()
78 | Path("foo.txt").open("w")
79 | text = Path("foo.txt").read_text()
   |        ^^^^^^^^^^^^^^^^^^^^^^^^^
80 | Path("foo.txt").write_text(text)
   |
help: Add explicit `encoding` argument
   |
78 | Path("foo.txt").open("w")
   - text = Path("foo.txt").read_text()
79 + text = Path("foo.txt").read_text(encoding="utf-8")
80 | Path("foo.txt").write_text(text)
   |
note: This is an unsafe fix and may change runtime behavior

PLW1514 [*] `pathlib.Path(...).write_text` without explicit `encoding` argument
  --> unspecified_encoding.py:80:1
   |
78 | Path("foo.txt").open("w")
79 | text = Path("foo.txt").read_text()
80 | Path("foo.txt").write_text(text)
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^
81 |
82 | # Non-errors.
   |
help: Add explicit `encoding` argument
   |
79 | text = Path("foo.txt").read_text()
   - Path("foo.txt").write_text(text)
80 + Path("foo.txt").write_text(text, encoding="utf-8")
81 |
   |
note: This is an unsafe fix and may change runtime behavior

PLW1514 [*] `pathlib.Path(...).open` in text mode without explicit `encoding` argument
  --> unspecified_encoding.py:96:1
   |
94 | # https://github.com/astral-sh/ruff/issues/19294
95 | x = Path("foo.txt")
96 | x.open()
   | ^^^^^^
97 |
98 | # https://github.com/astral-sh/ruff/issues/18107
   |
help: Add explicit `encoding` argument
   |
95 | x = Path("foo.txt")
   - x.open()
96 + x.open(encoding="utf-8")
97 |
   |
note: This is an unsafe fix and may change runtime behavior

PLW1514 [*] `pathlib.Path(...).open` in text mode without explicit `encoding` argument
   --> unspecified_encoding.py:105:10
    |
104 | def format_file(file: Path):
105 |     with file.open() as f:
    |          ^^^^^^^^^
106 |         contents = f.read()
    |
help: Add explicit `encoding` argument
    |
104 | def format_file(file: Path):
    -     with file.open() as f:
105 +     with file.open(encoding="utf-8") as f:
106 |         contents = f.read()
    |
note: This is an unsafe fix and may change runtime behavior
