flake8-simplify icon indicating copy to clipboard operation
flake8-simplify copied to clipboard

SIM905 false positive

Open Anthchirp opened this issue 1 year ago • 0 comments

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']

Anthchirp avatar Sep 16 '22 09:09 Anthchirp