astral-sh/ruff

Auto-fix for SIM103 could be improved or add a new SIM rule?

Open

#6184 aperta il 31 lug 2023

Vedi su GitHub
 (10 commenti) (0 reazioni) (0 assegnatari)Rust (2088 fork)batch import
acceptedhelp wantedrule

Metriche repository

Star
 (47.527 star)
Metriche merge PR
 (Merge medio 3g 8h) (573 PR mergiate in 30 g)

Descrizione

I came across this code on a project:

if not condition_a and condition_b:
    return True
elif condition_a and condition_b:
    return True
else:
    return False

condition_a is redundant and this entire snippet should be simplified to:

return bool(condition_b)

However, this is what ruff produced using ruff --select="SIM103" example.py --fix --isolated:

if not condition_a and condition_b:
  return True
return bool(condition_a and condition_b)

I think this is correct reading the rule docs but I thought there could be some improvement here either within this rule or a new rule.

Ruff version is 0.0.280 and config:

[tool.ruff]
line-length = 120
select = [
  "D3",  # pydocstyle
  "D40", # pydocstyle
  "DTZ", # flake8-datetimez
  "FLY", # flynt
  "I",   # isort
  "INT", # flake8-gettext
  "PIE", # flake8-pie
  "PLC", # pylint
  "PLE", # pylint
  "RSE", # flake8-raise
  "SIM2", # flake8-simplify
  "SIM3", # flake8-simplify
  "TCH", # flake8-type-checking
  "W",   # pycodestyle
  "YTT", # flake8-2020
]
target-version = "py37"

Guida contributor