Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Adjust rule] Drop SIM105 due to performance #91

Closed
atombrella opened this issue Feb 6, 2022 · 5 comments · Fixed by #93
Closed

[Adjust rule] Drop SIM105 due to performance #91

atombrella opened this issue Feb 6, 2022 · 5 comments · Fixed by #93
Assignees
Labels
enhancement New feature or request

Comments

@atombrella
Copy link

atombrella commented Feb 6, 2022

Desired change

  • Rule(s): SIM105
  • Adjustment: It should be dropped! Or at least highlight performance impact in the documentation!

Explanation

By conforming to this, the code will perform worse. Please check with timeit.

In [1]: %%timeit 
   ...: try: 
   ...:     a = {'a': 1} 
   ...:     a['b'] 
   ...: except KeyError: 
   ...:     pass 
   ...:                                                                                                                                                                                                    
199 ns ± 1.16 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)

In [5]: %%timeit 
   ...: with contextlib.suppress(KeyError): 
   ...:     a = {'a': 1} 
   ...:     a['b'] 
   ...:                                                                                                                                                                                                    
621 ns ± 6.38 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
@atombrella atombrella added the enhancement New feature or request label Feb 6, 2022
@atombrella atombrella changed the title [Adjust Rule] Drop SIM105 due to performance Feb 6, 2022
@atombrella
Copy link
Author

I found this repository because I followed your tutorial on Medium on how to write a flake8 plugin. Thanks a bunch for this! :)

@atombrella atombrella changed the title Drop SIM105 due to performance [Adjust rule] Drop SIM105 due to performance Feb 6, 2022
@MartinThoma
Copy link
Owner

Uh, interesting! I'll have a look and try to fix it this week.

Do you mind sharing the project where this time actually matters?

@MartinThoma
Copy link
Owner

Uh, I got your point wrong the first time : you're not worried about the runtime of sim105, but if the effect of the advocated change! Now I've got you! I'll document it tomorrow 👍

@atombrella
Copy link
Author

Uh, interesting! I'll have a look and try to fix it this week.

Do you mind sharing the project where this time actually matters?

django/django#9038 It's slow because of the way Python makes function calls.

@MartinThoma
Copy link
Owner

@atombrella What do you think about this? #93

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants