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

🔧 Added sourcery config file #811

Merged
merged 1 commit into from
Sep 11, 2021

Conversation

s-weigand
Copy link
Member

@s-weigand s-weigand commented Sep 11, 2021

Added sourcery config file and added 'simplify-boolean-comparison' to ignore.
This prevents expressions like if something is True to be refactored.

Background

'if something is True' prevents bugs where something is a callable, where 'if something():' would evaluate to False but 'if something:' evaluated to true since the callable object exists.

While using this explicit syntax creates a longer instruction list, the performance impact is neglectable.

In [1]: from dis import dis

In [2]: def foo():
   ...:     var = True
   ...:     if var is True:
   ...:         return False
   ...:

In [3]: def bar():
   ...:     var = True
   ...:     if var:
   ...:         return False
   ...:

In [4]: dis(foo)
  2           0 LOAD_CONST               1 (True)
              2 STORE_FAST               0 (var)

  3           4 LOAD_FAST                0 (var)
              6 LOAD_CONST               1 (True)
              8 COMPARE_OP               8 (is)
             10 POP_JUMP_IF_FALSE       16

  4          12 LOAD_CONST               2 (False)
             14 RETURN_VALUE
        >>   16 LOAD_CONST               0 (None)
             18 RETURN_VALUE

In [5]: dis(bar)
  2           0 LOAD_CONST               1 (True)
              2 STORE_FAST               0 (var)

  3           4 LOAD_FAST                0 (var)
              6 POP_JUMP_IF_FALSE       12

  4           8 LOAD_CONST               2 (False)
             10 RETURN_VALUE
        >>   12 LOAD_CONST               0 (None)
             14 RETURN_VALUE

In [6]: %timeit foo()
117 ns ± 0.643 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)

In [7]: %timeit bar()
115 ns ± 1.36 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)

Change summary

  • Added sourcery config file and added simplify-boolean-comparison to ignore

Checklist

  • ✔️ Passing the tests (mandatory for all PR's)

@s-weigand s-weigand requested a review from a team as a code owner September 11, 2021 21:20
@github-actions
Copy link
Contributor

Binder 👈 Launch a binder notebook on branch s-weigand/pyglotaran/configure-sourcery

@codecov
Copy link

codecov bot commented Sep 11, 2021

Codecov Report

Merging #811 (dffcac2) into staging (ae63eb4) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           staging    #811   +/-   ##
=======================================
  Coverage     84.5%   84.5%           
=======================================
  Files           75      75           
  Lines         4201    4201           
  Branches       757     757           
=======================================
  Hits          3553    3553           
  Misses         515     515           
  Partials       133     133           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ae63eb4...dffcac2. Read the comment docs.

and added 'simplify-boolean-comparison' to ignore
'if something is True' prevents bugs where something is a callable, where 'if something():' would evaluate to False but 'if something:' evaluated to true since the callable object exists.
Copy link
Member

@jsnel jsnel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌 LGTM

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@github-actions
Copy link
Contributor

Benchmark is done. Checkout the benchmark result page.
Benchmark differences below 5% might be due to CI noise.

Benchmark diff

Parametrized benchmark signatures:

BenchmarkOptimize.time_optimize(index_dependent, grouped, weight)

All benchmarks:

       before           after         ratio
     [dc00e6da]       [dffcac27]
     <v0.4.0>                   
-        43.0±1ms       32.4±0.1ms     0.75  BenchmarkOptimize.time_optimize(False, False, False)
-       245±0.8ms         37.1±1ms     0.15  BenchmarkOptimize.time_optimize(False, False, True)
-      63.6±0.2ms       53.7±0.3ms     0.84  BenchmarkOptimize.time_optimize(False, True, False)
-      65.4±0.3ms       56.9±0.3ms     0.87  BenchmarkOptimize.time_optimize(False, True, True)
         43.3±1ms       42.0±0.1ms     0.97  BenchmarkOptimize.time_optimize(True, False, False)
-         243±2ms        51.0±30ms     0.21  BenchmarkOptimize.time_optimize(True, False, True)
       63.5±0.3ms       64.6±0.4ms     1.02  BenchmarkOptimize.time_optimize(True, True, False)
       65.4±0.3ms        68.2±40ms     1.04  BenchmarkOptimize.time_optimize(True, True, True)
             182M             180M     0.99  IntegrationTwoDatasets.peakmem_create_result
             200M             195M     0.98  IntegrationTwoDatasets.peakmem_optimize
-         202±1ms          162±1ms     0.80  IntegrationTwoDatasets.time_create_result
-      4.33±0.01s       1.60±0.07s     0.37  IntegrationTwoDatasets.time_optimize

@jsnel jsnel merged commit 0f36985 into glotaran:staging Sep 11, 2021
@jsnel jsnel deleted the configure-sourcery branch September 11, 2021 22:05
jsnel pushed a commit that referenced this pull request Sep 16, 2021
Added 'simplify-boolean-comparison' to ignore
'if something is True' prevents bugs where something is a callable, where 'if something():' would evaluate to False but 'if something:' evaluated to true since the callable object exists.
@s-weigand
Copy link
Member Author

Just for reference when we need to tweak sourcery again here are the rules

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

Successfully merging this pull request may close these issues.

2 participants