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

Improve type hints #152

Merged
merged 10 commits into from
Nov 11, 2020
Merged

Improve type hints #152

merged 10 commits into from
Nov 11, 2020

Conversation

amolenaar
Copy link
Member

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Documentation content changes

What is the new behavior?

Gaphas is more specific on the types it accepts and how it handles those.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@amolenaar amolenaar added this to In progress in Gaphas overhaul via automation Nov 8, 2020
@amolenaar amolenaar added this to the 3.0 milestone Nov 8, 2020
Copy link
Member

@danyeaw danyeaw left a comment

Choose a reason for hiding this comment

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

For my knowledge, why was it better to move from a Sequence to a Collection?

A sequence includes integer indexed data structures like list, str, and tuple.
A collection includes list, dict, tuple, etc.

Are we trying to allow for passing in items that are in a dictionary?

@amolenaar
Copy link
Member Author

For my knowledge, why was it better to move from a Sequence to a Collection?

I was only trying to define the minimal interface required. Sequence is a subtype of Collection according to the docs:
https://docs.python.org/3/library/collections.abc.html.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Nov 11, 2020

Sourcery Code Quality Report

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

Quality metrics Before After Change
Complexity 1.04 ⭐ 0.98 ⭐ -0.06 👍
Method Length 36.74 ⭐ 35.29 ⭐ -1.45 👍
Working memory 5.20 ⭐ 5.07 ⭐ -0.13 👍
Quality 89.20% 89.69% 0.49% 👍
Other metrics Before After Change
Lines 3983 4073 90
Changed files Quality Before Quality After Quality Change
examples/demo.py 88.58% ⭐ 88.56% ⭐ -0.02% 👎
examples/exampleitems.py 87.25% ⭐ 90.48% ⭐ 3.23% 👍
gaphas/aspect.py 94.02% ⭐ 94.17% ⭐ 0.15% 👍
gaphas/canvas.py 94.26% ⭐ 94.14% ⭐ -0.12% 👎
gaphas/guide.py 84.56% ⭐ 84.56% ⭐ 0.00%
gaphas/item.py 91.37% ⭐ 92.63% ⭐ 1.26% 👍
gaphas/position.py 92.81% ⭐ 92.81% ⭐ 0.00%
gaphas/tree.py 90.96% ⭐ 91.01% ⭐ 0.05% 👍
gaphas/painter/boundingboxpainter.py 89.38% ⭐ 89.38% ⭐ 0.00%
gaphas/painter/chain.py 97.68% ⭐ 97.68% ⭐ 0.00%
gaphas/painter/focuseditempainter.py 95.50% ⭐ 95.50% ⭐ 0.00%
gaphas/painter/freehand.py 85.12% ⭐ 85.12% ⭐ 0.00%
gaphas/painter/handlepainter.py 77.52% ⭐ 77.52% ⭐ 0.00%
gaphas/painter/itempainter.py 92.69% ⭐ 92.69% ⭐ 0.00%
gaphas/painter/painter.py 100.00% ⭐ 100.00% ⭐ 0.00%
gaphas/painter/toolpainter.py 95.56% ⭐ 95.56% ⭐ 0.00%
gaphas/tool/init.py 83.64% ⭐ 83.15% ⭐ -0.49% 👎
gaphas/tool/handletool.py 81.82% ⭐ 87.14% ⭐ 5.32% 👍
gaphas/tool/itemtool.py 83.60% ⭐ 89.19% ⭐ 5.59% 👍
gaphas/tool/pan.py 79.42% ⭐ 79.45% ⭐ 0.03% 👍
gaphas/tool/placement.py 90.18% ⭐ 91.44% ⭐ 1.26% 👍
gaphas/tool/rubberband.py 86.09% ⭐ 86.12% ⭐ 0.03% 👍
gaphas/tool/textedit.py 87.57% ⭐ 87.60% ⭐ 0.03% 👍
gaphas/tool/tool.py 97.79% ⭐ 97.35% ⭐ -0.44% 👎
gaphas/tool/toolchain.py 88.11% ⭐ 87.29% ⭐ -0.82% 👎
gaphas/view/gtkview.py 84.43% ⭐ 84.25% ⭐ -0.18% 👎
gaphas/view/model.py 98.86% ⭐ 99.67% ⭐ 0.81% 👍
tests/test_aspect.py 92.91% ⭐ 92.13% ⭐ -0.78% 👎
tests/test_segment.py 78.45% ⭐ 78.46% ⭐ 0.01% 👍
tests/test_view.py 88.24% ⭐ 87.98% ⭐ -0.26% 👎

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

File Function Complexity Length Working Memory Quality Recommendation
examples/demo.py create_window 9 🙂 858 ⛔ 16 ⛔ 31.96% 😞 Try splitting into smaller methods. Extract out complex expressions
gaphas/view/gtkview.py GtkView.update_back_buffer 22 😞 231 ⛔ 11 😞 35.15% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
gaphas/painter/handlepainter.py HandlePainter._draw_handles 15 🙂 220 ⛔ 13 😞 37.74% 😞 Try splitting into smaller methods. Extract out complex expressions
gaphas/view/gtkview.py GtkView.get_handle_at_point 18 🙂 151 😞 10 😞 46.38% 😞 Try splitting into smaller methods. Extract out complex expressions
gaphas/view/gtkview.py GtkView.get_port_at_point 11 🙂 124 😞 14 😞 48.66% 😞 Try splitting into smaller methods. 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.

@amolenaar amolenaar mentioned this pull request Nov 11, 2020
7 tasks
@danyeaw danyeaw merged commit 13bbda1 into master Nov 11, 2020
Gaphas overhaul automation moved this from In progress to Done Nov 11, 2020
@danyeaw danyeaw deleted the iterables branch November 11, 2020 14:27
@danyeaw
Copy link
Member

danyeaw commented Nov 11, 2020

@amolenaar Nice refactoring! 🎉

@danyeaw danyeaw added the chore label Nov 23, 2020
@danyeaw danyeaw changed the title More type info Improve type hints Nov 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

2 participants