sourcery icon indicating copy to clipboard operation
sourcery copied to clipboard

Case sensitive list converter as one-liner

Open Anselmoo opened this issue 2 years ago • 1 comments

Checklist

  • [x] I think this refactoring is useful for everyone (if it's too specific, consider a custom rule)
  • [x] I have checked there are no similar issues suggesting the same thing

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 avatar Dec 29 '22 18:12 Anselmoo

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)

Anselmoo avatar Dec 29 '22 19:12 Anselmoo