mirror of https://github.com/astral-sh/ruff
[`pylint`] Add fix safety section (`PLR1722`) (#17826)
parent: #15584 fix introduced at: #816
This commit is contained in:
parent
ada4c4cb1f
commit
a4c8e43c5f
|
|
@ -19,6 +19,20 @@ use ruff_text_size::Ranged;
|
|||
/// Prefer `sys.exit()`, as the `sys` module is guaranteed to exist in all
|
||||
/// contexts.
|
||||
///
|
||||
/// ## Fix safety
|
||||
/// This fix is always unsafe. When replacing `exit` or `quit` with `sys.exit`,
|
||||
/// the behavior can change in the following ways:
|
||||
///
|
||||
/// 1. If the code runs in an environment where the `site` module is not imported
|
||||
/// (e.g., with `python -S`), the original code would raise a `NameError`, while
|
||||
/// the fixed code would execute normally.
|
||||
///
|
||||
/// 2. `site.exit` and `sys.exit` handle tuple arguments differently. `site.exit`
|
||||
/// treats tuples as regular objects and always returns exit code 1, while `sys.exit`
|
||||
/// interprets tuple contents to determine the exit code: an empty tuple () results in
|
||||
/// exit code 0, and a single-element tuple like (2,) uses that element's value (2) as
|
||||
/// the exit code.
|
||||
///
|
||||
/// ## Example
|
||||
/// ```python
|
||||
/// if __name__ == "__main__":
|
||||
|
|
|
|||
Loading…
Reference in New Issue