You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a python script that includes the following line:
"/my/endpoint".split("/")[-1]
When I run my script through pylint, it hits me with a use-maxsplit-arg warning and suggests I do the following instead:
"/my/endpoint".rsplit("/", maxsplit=1)[-1]
What I'm wondering is, what is the rationale behind that rule? It seems unnecessarily complex, and when I time things with timeit it looks like the recommended change actually takes slightly longer to execute than the original:
python -m timeit '"/my/endpoint".split("/")[-1]'
2000000 loops, best of 5: 124 nsec per loop
python -m timeit '"/my/endpoint".rsplit("/", maxsplit=1)[-1]'
2000000 loops, best of 5: 154 nsec per loop
Thanks!
Documentation for future user
This might already exist, but it'd be nice if there was an easy to access "rationale guide" behind some of these rules. Like I said, maybe that already exists but I wasn't able to find it quickly. I don't want to just make pylint ignore a rule because I don't understand it, but this one comes up often and I've never been able to figure out the rationale.
Additional context
No response
The text was updated successfully, but these errors were encountered:
I wasn't involved in reviewing that checker, but it looks like speed was the reason. You can imagine this making a bigger difference with a larger string:
We're working on a documentation project to provide a page for each message. I could envision adding a sentence about this there, acknowledging that there is negligible or even worse performance impact with such small strings. I'll just open that PR to get it going.
Question
I have a python script that includes the following line:
When I run my script through
pylint
, it hits me with ause-maxsplit-arg
warning and suggests I do the following instead:What I'm wondering is, what is the rationale behind that rule? It seems unnecessarily complex, and when I time things with
timeit
it looks like the recommended change actually takes slightly longer to execute than the original:Thanks!
Documentation for future user
This might already exist, but it'd be nice if there was an easy to access "rationale guide" behind some of these rules. Like I said, maybe that already exists but I wasn't able to find it quickly. I don't want to just make pylint ignore a rule because I don't understand it, but this one comes up often and I've never been able to figure out the rationale.
Additional context
No response
The text was updated successfully, but these errors were encountered: