Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flake8-simplify] Do not emit diagnostics for expressions inside string type annotations (SIM222, SIM223) #15405

Merged
merged 2 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,7 @@ def secondToTime(s0: int) -> ((int, int, int) or str):

for x in {**a, **b} or [None]:
pass


# https://github.com/astral-sh/ruff/issues/7127
def f(a: "'b' or 'c'"): ...
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,7 @@
print(f"{a}{''}" and "bar")
print(f"{''}{''}" and "bar")
print(f"{1}{''}" and "bar")


# https://github.com/astral-sh/ruff/issues/7127
def f(a: "'' and 'b'"): ...
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,10 @@ fn is_short_circuit(

/// SIM222
pub(crate) fn expr_or_true(checker: &mut Checker, expr: &Expr) {
if checker.semantic().in_string_type_definition() {
return;
}

if let Some((edit, remove)) = is_short_circuit(expr, BoolOp::Or, checker) {
let mut diagnostic = Diagnostic::new(
ExprOrTrue {
Expand All @@ -848,6 +852,10 @@ pub(crate) fn expr_or_true(checker: &mut Checker, expr: &Expr) {

/// SIM223
pub(crate) fn expr_and_false(checker: &mut Checker, expr: &Expr) {
if checker.semantic().in_string_type_definition() {
return;
}

if let Some((edit, remove)) = is_short_circuit(expr, BoolOp::And, checker) {
let mut diagnostic = Diagnostic::new(
ExprAndFalse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1023,3 +1023,5 @@ SIM223.py:154:7: SIM223 [*] Use `f"{''}{''}"` instead of `f"{''}{''}" and ...`
154 |-print(f"{''}{''}" and "bar")
154 |+print(f"{''}{''}")
155 155 | print(f"{1}{''}" and "bar")
156 156 |
157 157 |
Loading