Skip to content

Sourcery refactored main branch#27

Closed
sourcery-ai[bot] wants to merge 1 commit into
mainfrom
sourcery/main
Closed

Sourcery refactored main branch#27
sourcery-ai[bot] wants to merge 1 commit into
mainfrom
sourcery/main

Conversation

@sourcery-ai
Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot commented Dec 14, 2020

Branch main refactored by Sourcery.

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

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 main branch, then run:

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

@sourcery-ai sourcery-ai Bot requested a review from ks129 as a code owner December 14, 2020 21:38
@ghost
Copy link
Copy Markdown

ghost commented Dec 14, 2020

Thank you for contributing to Python Discord!

Please check out the following documents:

@sourcery-ai sourcery-ai Bot requested a review from jb3 December 14, 2020 21:38
Comment thread backend/route_manager.py
Comment on lines -40 to +61
if inspect.isclass(member):
if issubclass(member, Route) and member != Route:
member.check_parameters()

levels = str(file.parent).split("/")[2:]

current_level = None
for level in levels:
if current_level is None:
current_level = route_dict[f"/{level}"]
else:
current_level = current_level[f"/{level}"]

if current_level is not None:
current_level[member.path] = member
if (
inspect.isclass(member)
and issubclass(member, Route)
and member != Route
):
member.check_parameters()

levels = str(file.parent).split("/")[2:]

current_level = None
for level in levels:
if current_level is None:
current_level = route_dict[f"/{level}"]
else:
route_dict[member.path] = member
current_level = current_level[f"/{level}"]

route_map = construct_route_map_from_dict(route_dict.to_dict())
if current_level is not None:
current_level[member.path] = member
else:
route_dict[member.path] = member

return route_map
return construct_route_map_from_dict(route_dict.to_dict())
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function create_route_map refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)
  • Merge nested if conditions (merge-nested-ifs)

Comment thread backend/models/form.py
Comment on lines -28 to +29
allowed_values = list(v.value for v in FormFeatures.__members__.values())
if not all(v in allowed_values for v in value):
allowed_values = [v.value for v in FormFeatures.__members__.values()]
if any(v not in allowed_values for v in value):
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function Form.validate_features refactored with the following changes:

  • Invert any/all to simplify comparisons (invert-any-all)
  • Replace list(), dict() or set() with comprehension (collection-builtin-to-comprehension)

@ghost ghost added the needs 1 approval label Dec 14, 2020
@sourcery-ai
Copy link
Copy Markdown
Author

sourcery-ai Bot commented Dec 14, 2020

Sourcery Code Quality Report

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

Quality metrics Before After Change
Complexity 15.76 🙂 12.36 🙂 -3.40 👍
Method Length 56.33 ⭐ 55.17 ⭐ -1.16 👍
Working memory 10.39 😞 10.11 😞 -0.28 👍
Quality 57.40% 🙂 60.66% 🙂 3.26% 👍
Other metrics Before After Change
Lines 95 96 1
Changed files Quality Before Quality After Quality Change
backend/route_manager.py 46.89% 😞 50.91% 🙂 4.02% 👍
backend/models/form.py 72.64% 🙂 73.81% 🙂 1.17% 👍

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

File Function Complexity Length Working Memory Quality Recommendation
backend/route_manager.py create_route_map 22 😞 131 😞 13 😞 40.57% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
backend/models/form.py Form.dict 9 🙂 54 ⭐ 10 😞 67.06% 🙂 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.

@jb3 jb3 closed this Dec 14, 2020
@jb3 jb3 deleted the sourcery/main branch December 14, 2020 21:41
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.

1 participant