Skip to content

Commit a4c8e43

Browse files
authored
[pylint] Add fix safety section (PLR1722) (#17826)
parent: #15584 fix introduced at: #816
1 parent ada4c4c commit a4c8e43

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ use ruff_text_size::Ranged;
1919
/// Prefer `sys.exit()`, as the `sys` module is guaranteed to exist in all
2020
/// contexts.
2121
///
22+
/// ## Fix safety
23+
/// This fix is always unsafe. When replacing `exit` or `quit` with `sys.exit`,
24+
/// the behavior can change in the following ways:
25+
///
26+
/// 1. If the code runs in an environment where the `site` module is not imported
27+
/// (e.g., with `python -S`), the original code would raise a `NameError`, while
28+
/// the fixed code would execute normally.
29+
///
30+
/// 2. `site.exit` and `sys.exit` handle tuple arguments differently. `site.exit`
31+
/// treats tuples as regular objects and always returns exit code 1, while `sys.exit`
32+
/// interprets tuple contents to determine the exit code: an empty tuple () results in
33+
/// exit code 0, and a single-element tuple like (2,) uses that element's value (2) as
34+
/// the exit code.
35+
///
2236
/// ## Example
2337
/// ```python
2438
/// if __name__ == "__main__":

0 commit comments

Comments
 (0)