tonybaloney / perflint

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

R8203 no longer valid for CPython 3.11+ #37

Closed HacKanCuBa closed 10 months ago

HacKanCuBa commented 2 years ago

First of all, thanks for perflint, I love it :D

Now, to the issue at hand: CPython 3.11 implemented zero-cost exception handling (1, 2), therefore a try/except block inside a loop is no longer a perf issue, as it would be wrongfully stated by R8203: Try..except blocks have an overhead. Avoid using them inside a loop unless you're using them for control-flow. (loop-try-except-usage).

Now, I do understand that detecting the Python version being used by the script being analyzed might not be at all possible, but maybe it would be nice to clarify in the message that it does not apply to CPython 3.11+, as it would discourage writing actually performant try/except blocks.

tonybaloney commented 2 years ago

Great point. It doesn't make sense to raise this in 3.11+