MartinThoma / flake8-simplify

❄ A flake8 plugin that helps you to simplify code
MIT License
187 stars 19 forks source link

SIM905 false positive #153

Open Anthchirp opened 2 years ago

Anthchirp commented 2 years ago

Explanation

SIM905 incorrectly identifies cases where split is used with arguments

Example

This is an example where the mentioned rule(s) would currently be suboptimal:

from pprint import pprint

things = """
some configuration
  - a
  - b
  - more:
    - d
    - e
""".split("\n")

pprint(things)

SIM905 rule output:

example.py:3:10: SIM905 Use '["some", "configuration", "-", "a", "-", "b", "-", "more:", "-", "d", "-", "e"]' instead of '"
some configuration
  - a
  - b
  - more:
    - d
    - e
".split()'

This is different from the program output:

$ python example.py
['',
 'some configuration',
 '  - a',
 '  - b',
 '  - more:',
 '    - d',
 '    - e',
 '']

Example with maxsplit

from pprint import pprint

things = """
some configuration
  - a
  - b
  - more:
    - d
    - e
""".split(sep=None, maxsplit=2)

pprint(things)

SIM905 rule output:

example.py:3:10: SIM905 Use '["some", "configuration", "-", "a", "-", "b", "-", "more:", "-", "d", "-", "e"]' instead of '"
some configuration
  - a
  - b
  - more:
    - d
    - e
".split()'

This is different from the program output:

$ python example.py
['some', 'configuration', '- a\n  - b\n  - more:\n    - d\n    - e\n']