sourcery icon indicating copy to clipboard operation
sourcery copied to clipboard

Refactor .split("\n") to .splitlines()

Open alwinw opened this issue 2 years ago • 2 comments

Issue description or question

Feature request for refactoring python code to make it more pythonic.

Suggest refactoring .split("\n") to splitlines().

Sourcery Version

v0.11.2

Code editor or IDE name and version

VSCode

OS name and version

Windows

P.S. Sourcery is great!

alwinw avatar Apr 12 '22 00:04 alwinw

Hey @alwinw, thank you for this suggestion! I've added it to our pipeline.

The tricky piece here is that this could change functionality since s.split("\n") and s.splitlines() behave differently in certain situations (for instance, when s is an empty string). Could you please share a bit about your use case? Maybe we can determine the right conditions for Sourcery to suggest this change.

ruancomelli avatar Apr 12 '22 13:04 ruancomelli

Hey @ruancomelli thanks for the speedy response. That's a great point, I didn't realise it behaves differently in some situations.

The primary situation I have in mind is reading a file and converting each line to a string for some subsequent processing.

alwinw avatar Apr 14 '22 12:04 alwinw