btclib-org / btclib

btclib: a python3 library for 'bitcoin cryptography'
https://btclib.org
MIT License
97 stars 42 forks source link

Script interpreter (Sourcery refactored) #84

Closed sourcery-ai[bot] closed 1 year ago

sourcery-ai[bot] commented 1 year ago

Pull Request #83 refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

NOTE: As code is pushed to the original Pull Request, Sourcery will re-run and update (force-push) this Pull Request with new refactorings as necessary. If Sourcery finds no refactorings at any point, this Pull Request will be closed automatically.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the script_engine branch, then run:

git fetch origin sourcery/script_engine
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

sourcery-ai[bot] commented 1 year ago

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 0.03%.

Quality metrics Before After Change
Complexity 4.37 ⭐ 4.28 ⭐ -0.09 👍
Method Length 90.29 🙂 89.93 🙂 -0.36 👍
Working memory 7.95 🙂 7.98 🙂 0.03 👎
Quality 66.37% 🙂 66.40% 🙂 0.03% 👍
Other metrics Before After Change
Lines 3678 3669 -9
Changed files Quality Before Quality After Quality Change
btclib/psbt/psbt.py 60.43% 🙂 60.01% 🙂 -0.42% 👎
btclib/psbt/psbt_utils.py 84.31% ⭐ 84.45% ⭐ 0.14% 👍
btclib/script/script.py 65.08% 🙂 65.10% 🙂 0.02% 👍
btclib/script/script_pub_key.py 78.13% ⭐ 78.18% ⭐ 0.05% 👍
btclib/script/sig_hash.py 42.89% 😞 43.01% 😞 0.12% 👍
btclib/script/taproot.py 52.96% 🙂 53.24% 🙂 0.28% 👍
tests/test_b32.py 80.10% ⭐ 80.08% ⭐ -0.02% 👎
tests/test_b58.py 69.41% 🙂 69.35% 🙂 -0.06% 👎
tests/script/test_script_pub_key.py 69.32% 🙂 69.33% 🙂 0.01% 👍
tests/script/test_sig_hash_taproot.py 56.57% 🙂 56.60% 🙂 0.03% 👍
tests/script/test_taproot.py 78.70% ⭐ 79.17% ⭐ 0.47% 👍
tests/tx/test_tx.py 60.00% 🙂 60.01% 🙂 0.01% 👍

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
btclib/script/taproot.py parse 33 ⛔ 182 😞 14 😞 28.00% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
btclib/script/sig_hash.py taproot 13 🙂 330 ⛔ 18 ⛔ 29.11% 😞 Try splitting into smaller methods. Extract out complex expressions
btclib/script/sig_hash.py legacy 19 😞 257 ⛔ 12 😞 34.12% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
btclib/script/script.py parse 25 😞 154 😞 14 😞 34.72% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
tests/script/test_sig_hash_taproot.py test_invalid_taproot_key_path 14 🙂 224 ⛔ 15 😞 35.64% 😞 Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!