tonybaloney / perflint

Python Linter for performance anti patterns
MIT License
659 stars 10 forks source link

``use-tuple-over-list`` already exists in pylint in the "code style" extensions as ``consider-using-tuple`` #23

Open Pierre-Sassoulas opened 2 years ago

Pierre-Sassoulas commented 2 years ago

https://pylint.pycqa.org/en/latest/messages/refactor/consider-using-tuple.html

There was a discussion about the performance benefits and we concluded that it's a style check and not a performance check. Feel free to chime in :)

For reference I'm trying to integrate the check in pylint here: https://github.com/PyCQA/pylint/pull/6078

tonybaloney commented 2 years ago

Thanks! I wonder why it didn't flag that on my test cases then. I'll have another look

Pierre-Sassoulas commented 2 years ago

It might be because this needs to be activated explicitly (it's an extension). The conversation is long but should clear up the reasoning behind the use-set-for-membership message that was added alongside it.

woctezuma commented 1 year ago

Maybe the README should be updated.

In the README of perflint:

Constructing a tuple is faster than a list and indexing tuples is faster. When the sequence is not mutated, then a tuple should be used instead.

vs. on the website of pylint:

Only for style consistency! Emitted where an in-place defined list can be replaced by a tuple. Due to optimizations by CPython, there is no performance benefit from it.