Skip to content

[Adjust rule] Drop SIM105 due to performance #91

@atombrella

Description

@atombrella

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)

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions