Fix docs for `PLW1508` (#6602)

This commit is contained in:
Zanie Blue 2023-08-15 15:29:29 -05:00 committed by GitHub
parent a3d4f08f29
commit 097db2fcce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 6 deletions

View File

@ -5,25 +5,29 @@ use ruff_python_ast::{self as ast, Constant, Expr, Operator, Ranged};
use crate::checkers::ast::Checker;
/// ## What it does
/// Checks for `env.getenv` calls with invalid default values.
/// Checks for `os.getenv` calls with invalid default values.
///
/// ## Why is this bad?
/// If an environment variable is set, `env.getenv` will return its value as
/// a string. If the environment variable is _not_ set, `env.getenv` will
/// If an environment variable is set, `os.getenv` will return its value as
/// a string. If the environment variable is _not_ set, `os.getenv` will
/// return `None`, or the default value if one is provided.
///
/// If the default value is not a string or `None`, then it will be
/// inconsistent with the return type of `env.getenv`, which can lead to
/// inconsistent with the return type of `os.getenv`, which can lead to
/// confusing behavior.
///
/// ## Example
/// ```python
/// int(env.getenv("FOO", 1))
/// import os
///
/// int(os.getenv("FOO", 1))
/// ```
///
/// Use instead:
/// ```python
/// int(env.getenv("FOO", "1"))
/// import os
///
/// int(os.getenv("FOO", "1"))
/// ```
#[violation]
pub struct InvalidEnvvarDefault;