Skip to content

Commit b398b83

Browse files
authored
[pylint] add fix safety section (PLW1514) (#17932)
parent #15584 fix was made unsafe at #8928
1 parent bc7b303 commit b398b83

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

crates/ruff_linter/src/rules/pylint/rules/unspecified_encoding.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ use crate::fix::edits::add_argument;
2828
/// Python 3.10 and later, or `locale.getpreferredencoding()` on earlier versions,
2929
/// to make the encoding explicit.
3030
///
31+
/// ## Fix safety
32+
/// This fix is always unsafe and may change the program's behavior. It forces
33+
/// `encoding="utf-8"` as the default, regardless of the platform’s actual default
34+
/// encoding, which may cause `UnicodeDecodeError` on non-UTF-8 systems.
35+
/// ```python
36+
/// with open("test.txt") as f:
37+
/// print(f.read()) # before fix (on UTF-8 systems): 你好,世界!
38+
/// with open("test.txt", encoding="utf-8") as f:
39+
/// print(f.read()) # after fix (on Windows): UnicodeDecodeError
40+
/// ```
41+
///
3142
/// ## Example
3243
/// ```python
3344
/// open("file.txt")

0 commit comments

Comments
 (0)