mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-27 12:29:28 +00:00
Allow string percent formatting in os.getenv (#3518)
This commit is contained in:
parent
1b738f88c4
commit
c50d6da8b4
3 changed files with 23 additions and 1 deletions
|
@ -8,5 +8,5 @@ os.getenv("AA", "GOOD")
|
||||||
os.getenv("AA", f"GOOD")
|
os.getenv("AA", f"GOOD")
|
||||||
os.getenv("AA", "GOOD" + "BAD")
|
os.getenv("AA", "GOOD" + "BAD")
|
||||||
os.getenv("AA", "GOOD" + 1)
|
os.getenv("AA", "GOOD" + 1)
|
||||||
|
os.getenv("AA", "GOOD %s" % "BAD")
|
||||||
os.getenv("B", Z)
|
os.getenv("B", Z)
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,7 @@ fn is_valid_default(expr: &Expr) -> bool {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Allow string concatenation.
|
||||||
if let ExprKind::BinOp {
|
if let ExprKind::BinOp {
|
||||||
left,
|
left,
|
||||||
right,
|
right,
|
||||||
|
@ -58,6 +59,16 @@ fn is_valid_default(expr: &Expr) -> bool {
|
||||||
return is_valid_default(left) && is_valid_default(right);
|
return is_valid_default(left) && is_valid_default(right);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Allow string formatting.
|
||||||
|
if let ExprKind::BinOp {
|
||||||
|
left,
|
||||||
|
op: Operator::Mod,
|
||||||
|
..
|
||||||
|
} = &expr.node
|
||||||
|
{
|
||||||
|
return is_valid_default(left);
|
||||||
|
}
|
||||||
|
|
||||||
// Otherwise, the default must be a string or `None`.
|
// Otherwise, the default must be a string or `None`.
|
||||||
matches!(
|
matches!(
|
||||||
expr.node,
|
expr.node,
|
||||||
|
|
|
@ -46,6 +46,7 @@ fn is_valid_key(expr: &Expr) -> bool {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Allow string concatenation.
|
||||||
if let ExprKind::BinOp {
|
if let ExprKind::BinOp {
|
||||||
left,
|
left,
|
||||||
right,
|
right,
|
||||||
|
@ -55,6 +56,16 @@ fn is_valid_key(expr: &Expr) -> bool {
|
||||||
return is_valid_key(left) && is_valid_key(right);
|
return is_valid_key(left) && is_valid_key(right);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Allow string formatting.
|
||||||
|
if let ExprKind::BinOp {
|
||||||
|
left,
|
||||||
|
op: Operator::Mod,
|
||||||
|
..
|
||||||
|
} = &expr.node
|
||||||
|
{
|
||||||
|
return is_valid_key(left);
|
||||||
|
}
|
||||||
|
|
||||||
// Otherwise, the default must be a string.
|
// Otherwise, the default must be a string.
|
||||||
matches!(
|
matches!(
|
||||||
expr.node,
|
expr.node,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue