sourcery-ai / sourcery

Instant AI code reviews
https://sourcery.ai
MIT License
1.51k stars 65 forks source link

Case sensitive list converter as one-liner #312

Open Anselmoo opened 1 year ago

Anselmoo commented 1 year ago

Checklist

Description

Sourcery already suggests dependencies as one-liners. There might be a new one for creating optional list

Code Before

In case you have work in your functions or class with iterators.

def example(func_name: str | list[str]):
      if isinstance(func_name, str):
            func_name = [func_name]

Code After

def example(func_name: str | list[str]):
      func_name = [func_name] if isinstance(func_name, str) else func_name
Anselmoo commented 1 year ago

In addition to that, would it make sense for default-mutable-arg to change from:

From:

def func(hats: list = None):
    if hats is None:
        hats = []
    change(hats)

to:

def func(hats: list = None):
    hats = hats or []
    change(hats)