Skip to content

SIM108 turns readable code into unreadable code #5528

@karolinepauls

Description

@karolinepauls

The rule should only apply to trivial conditions with the simplest expressions (e.g. even having 2 sub-expressions joined with and or or is too much).

a.py:

from typing import Optional

# an ugly but realistic type
something: Optional[list] = None

if something is not None and len(something) > 1:
    runner_image = something[0].url
else:
    runner_image = None

cmd: ruff --isolated --select SIM --line-length=120 a.py

Output:

a.py:5:1: SIM108 [*] Use ternary operator `runner_image = something[0].url if something is not None and len(something) > 1 else None` instead of `if`-`else`-block

My eyes refuse to read runner_image = something[0].url if something is not None and len(something) > 1 else None.

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-decisionAwaiting a decision from a maintainerruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions