mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 18:58:04 +00:00
T201/T203 Improve print/pprint docs (#18130)
Some checks are pending
CI / cargo fmt (push) Waiting to run
CI / Determine changes (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
CI / benchmarks (push) Blocked by required conditions
Some checks are pending
CI / cargo fmt (push) Waiting to run
CI / Determine changes (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
CI / benchmarks (push) Blocked by required conditions
Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
parent
dd04ca7f58
commit
660375d429
1 changed files with 35 additions and 17 deletions
|
@ -11,26 +11,42 @@ use crate::registry::AsRule;
|
|||
/// Checks for `print` statements.
|
||||
///
|
||||
/// ## Why is this bad?
|
||||
/// `print` statements are useful in some situations (e.g., debugging), but
|
||||
/// should typically be omitted from production code. `print` statements can
|
||||
/// lead to the accidental inclusion of sensitive information in logs, and are
|
||||
/// not configurable by clients, unlike `logging` statements.
|
||||
/// `print` statements used for debugging should be omitted from production
|
||||
/// code. They can lead the accidental inclusion of sensitive information in
|
||||
/// logs, and are not configurable by clients, unlike `logging` statements.
|
||||
///
|
||||
/// `print` statements used to produce output as a part of a command-line
|
||||
/// interface program are not typically a problem.
|
||||
///
|
||||
/// ## Example
|
||||
/// ```python
|
||||
/// def add_numbers(a, b):
|
||||
/// print(f"The sum of {a} and {b} is {a + b}")
|
||||
/// return a + b
|
||||
/// def sum_less_than_four(a, b):
|
||||
/// print(f"Calling sum_less_than_four")
|
||||
/// return a + b < 4
|
||||
/// ```
|
||||
///
|
||||
/// Use instead:
|
||||
/// The automatic fix will remove the print statement entirely:
|
||||
///
|
||||
/// ```python
|
||||
/// def add_numbers(a, b):
|
||||
/// return a + b
|
||||
/// def sum_less_than_four(a, b):
|
||||
/// return a + b < 4
|
||||
/// ```
|
||||
///
|
||||
/// To keep the line for logging purposes, instead use something like:
|
||||
///
|
||||
/// ```python
|
||||
/// import logging
|
||||
///
|
||||
/// logging.basicConfig(level=logging.INFO)
|
||||
///
|
||||
///
|
||||
/// def sum_less_than_four(a, b):
|
||||
/// logging.debug("Calling sum_less_than_four")
|
||||
/// return a + b < 4
|
||||
/// ```
|
||||
///
|
||||
/// ## Fix safety
|
||||
/// This rule's fix is marked as unsafe, as it may remove `print` statements
|
||||
/// This rule's fix is marked as unsafe, as it will remove `print` statements
|
||||
/// that are used beyond debugging purposes.
|
||||
#[derive(ViolationMetadata)]
|
||||
pub(crate) struct Print;
|
||||
|
@ -52,11 +68,13 @@ impl Violation for Print {
|
|||
/// Checks for `pprint` statements.
|
||||
///
|
||||
/// ## Why is this bad?
|
||||
/// Like `print` statements, `pprint` statements are useful in some situations
|
||||
/// (e.g., debugging), but should typically be omitted from production code.
|
||||
/// `pprint` statements can lead to the accidental inclusion of sensitive
|
||||
/// information in logs, and are not configurable by clients, unlike `logging`
|
||||
/// statements.
|
||||
/// Like `print` statements, `pprint` statements used for debugging should
|
||||
/// be omitted from production code. They can lead the accidental inclusion
|
||||
/// of sensitive information in logs, and are not configurable by clients,
|
||||
/// unlike `logging` statements.
|
||||
///
|
||||
/// `pprint` statements used to produce output as a part of a command-line
|
||||
/// interface program are not typically a problem.
|
||||
///
|
||||
/// ## Example
|
||||
/// ```python
|
||||
|
@ -77,7 +95,7 @@ impl Violation for Print {
|
|||
/// ```
|
||||
///
|
||||
/// ## Fix safety
|
||||
/// This rule's fix is marked as unsafe, as it may remove `pprint` statements
|
||||
/// This rule's fix is marked as unsafe, as it will remove `pprint` statements
|
||||
/// that are used beyond debugging purposes.
|
||||
#[derive(ViolationMetadata)]
|
||||
pub(crate) struct PPrint;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue