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

fix: cleaner IPython import completion for Python 3.7+ #179

Merged
merged 1 commit into from Apr 8, 2021

Conversation

henryiii
Copy link
Member

@henryiii henryiii commented Apr 8, 2021

I’ve used Python 3.7 module-level __getattr__ for a while now to allow mistyping hist.axis import as hist.axes to show a warning but work anyway. However, I completely missed a fantastic usage for Python 3.7 module-level __dir__ : you can “fix” IPython’s tab completion to just show the items in __all__! Wow! One of the main things that bugged me about importing and defining unrelated things in modules, and one reason that boost-histogram has an _internal module. It was almost a parenthetical comment on the classic article here: https://snarky.ca/lazy-importing-in-python-3-7/

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Apr 8, 2021

Sourcery Code Quality Report

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

Quality metrics Before After Change
Complexity 10.61 🙂 10.21 🙂 -0.40 👍
Method Length 67.91 🙂 58.23 ⭐ -9.68 👍
Working memory 14.32 😞 13.72 😞 -0.60 👍
Quality 49.76% 😞 51.88% 🙂 2.12% 👍
Other metrics Before After Change
Lines 713 722 9
Changed files Quality Before Quality After Quality Change
src/hist/init.py 84.75% ⭐ 89.99% ⭐ 5.24% 👍
src/hist/axestuple.py 87.67% ⭐ 88.97% ⭐ 1.30% 👍
src/hist/plot.py 37.05% 😞 37.70% 😞 0.65% 👍
src/hist/tag.py 83.29% ⭐ 83.29% ⭐ 0.00%
src/hist/typing.py 78.72% ⭐ 84.68% ⭐ 5.96% 👍
src/hist/axis/init.py 79.74% ⭐ 81.98% ⭐ 2.24% 👍

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

File Function Complexity Length Working Memory Quality Recommendation
src/hist/plot.py plot_pull 23 😞 716 ⛔ 22 ⛔ 16.50% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
src/hist/plot.py plot2d_full 9 🙂 278 ⛔ 14 😞 38.61% 😞 Try splitting into smaller methods. Extract out complex expressions
src/hist/plot.py _curve_fit_wrapper 5 ⭐ 156 😞 14 😞 50.72% 🙂 Try splitting into smaller methods. Extract out complex expressions
src/hist/plot.py _expr_to_lambda 9 🙂 129 😞 11 😞 54.60% 🙂 Try splitting into smaller methods. Extract out complex expressions
src/hist/axis/init.py Regular.__init__ 2 ⭐ 71 🙂 18 ⛔ 60.35% 🙂 Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

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!

Let us know what you think of it by mentioning @sourcery-ai in a comment.

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.

None yet

1 participant