Skip to content

Sourcery refactored master branch #1

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Dec 5, 2021

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

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

Help us improve this pull request!

@height
Copy link

height bot commented Dec 5, 2021

Link Height tasks by mentioning a task ID in the pull request title or commit messages, or description and comments with the keyword link (e.g. "Link T-123").

💡Tip: You can also use "Close T-X" to automatically close a task when the pull request is merged.

@sourcery-ai sourcery-ai bot requested a review from admariner December 5, 2021 11:21
Comment on lines -55 to +59
keywords = {}
for keyword in suite.resource.keywords:
keywords[keyword.name] = keyword
keywords = {keyword.name: keyword for keyword in suite.resource.keywords}
suite.resource.keywords._items = list(keywords.values())

# Strip duplicate variables
variables = {}
for variable in suite.resource.variables:
variables[variable.name] = variable
variables = {variable.name: variable for variable in suite.resource.variables}
Copy link
Author

Choose a reason for hiding this comment

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

Function build_suite refactored with the following changes:

Comment on lines -10 to +14
matches = []

for lib in list(STDLIBS) + list(get_root_modules()):
if needle in lib.lower():
matches.append(lib)

return matches
return [
lib
for lib in list(STDLIBS) + list(get_root_modules())
if needle in lib.lower()
]
Copy link
Author

Choose a reason for hiding this comment

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

Function complete_libraries refactored with the following changes:

header = rpa and "Tasks" or "Test Cases"
header = "Tasks" if rpa else "Test Cases"
Copy link
Author

Choose a reason for hiding this comment

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

Function execute_python.execute_ipywidget refactored with the following changes:

remained = []
for driver in drivers:
if driver.get("type") != type_:
remained.append(driver)
remained = [driver for driver in drivers if driver.get("type") != type_]
Copy link
Author

Choose a reason for hiding this comment

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

Function clear_drivers refactored with the following changes:

Comment on lines -192 to +194
aliases = []
for alias, idx_ in cache._aliases.items():
if (idx + 1) == idx_:
aliases.append(alias)
aliases = [
alias
for alias, idx_ in cache._aliases.items()
if (idx + 1) == idx_
]

Copy link
Author

Choose a reason for hiding this comment

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

Function get_webdrivers refactored with the following changes:

Comment on lines -462 to +460
results = []
matches = []
unresolved = []
if needle:
results = driver.find_elements_by_xpath(needle)
results = driver.find_elements_by_xpath(needle) if needle else []
Copy link
Author

Choose a reason for hiding this comment

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

Function get_selenium_xpath_selector_completions refactored with the following changes:

Comment on lines -47 to +51
if as_bytes:
fp = MemoryStream()
screenshot.Save(fp, ImageFormat.Png)
return bytes(bytearray(fp.ToArray()))
else:
if not as_bytes:
return screenshot
fp = MemoryStream()
screenshot.Save(fp, ImageFormat.Png)
return bytes(bytearray(fp.ToArray()))
Copy link
Author

Choose a reason for hiding this comment

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

Function PickSnipTool.take_screenshot refactored with the following changes:

Comment on lines -87 to +92
if s and not s.startswith("*") and not s.startswith("["):
if s.count("."):
library, name = s.rsplit(".", 1)
return library + "." + name[0].title() + name[1:].lower()
else:
return s[0].title() + s[1:].lower()
else:
if not s or s.startswith("*") or s.startswith("["):
return s
if not s.count("."):
return s[0].title() + s[1:].lower()
library, name = s.rsplit(".", 1)
return library + "." + name[0].title() + name[1:].lower()
Copy link
Author

Choose a reason for hiding this comment

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

Function readable_keyword refactored with the following changes:

Comment on lines +102 to +112
context_name = context_parts[1].strip().lower()
if context_name == "settings":
return "__settings__"
elif line.lstrip() == line:
return "__root__"
elif context_name in ["tasks", "test cases"]:
return "__tasks__"
elif context_name == "keywords":
return "__keywords__"
else:
context_name = context_parts[1].strip().lower()
if context_name == "settings":
return "__settings__"
elif line.lstrip() == line:
return "__root__"
elif context_name in ["tasks", "test cases"]:
return "__tasks__"
elif context_name == "keywords":
return "__keywords__"
else:
return "__root__"
return "__root__"
Copy link
Author

Choose a reason for hiding this comment

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

Function detect_robot_context refactored with the following changes:

Comment on lines -236 to +237
else:
data, metadata = JSON(data=obj, expanded=True)._repr_json_()
return (
{"application/json": data, "text/html": f"<pre>{to_html(obj)}</pre>"},
metadata,
)
data, metadata = JSON(data=obj, expanded=True)._repr_json_()
return (
{"application/json": data, "text/html": f"<pre>{to_html(obj)}</pre>"},
metadata,
)
Copy link
Author

Choose a reason for hiding this comment

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

Function to_mime_and_metadata refactored with the following changes:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Dec 5, 2021

Sourcery Code Quality Report

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

Quality metrics Before After Change
Complexity 8.48 ⭐ 8.27 ⭐ -0.21 👍
Method Length 59.57 ⭐ 59.24 ⭐ -0.33 👍
Working memory 8.71 🙂 8.66 🙂 -0.05 👍
Quality 65.50% 🙂 65.80% 🙂 0.30% 👍
Other metrics Before After Change
Lines 1812 1790 -22
Changed files Quality Before Quality After Quality Change
src/robotkernel/builders_32.py 63.67% 🙂 66.41% 🙂 2.74% 👍
src/robotkernel/completion_finders.py 88.23% ⭐ 95.18% ⭐ 6.95% 👍
src/robotkernel/executors.py 43.76% 😞 43.82% 😞 0.06% 👍
src/robotkernel/listeners.py 82.26% ⭐ 82.89% ⭐ 0.63% 👍
src/robotkernel/monkeypatches.py 67.00% 🙂 68.51% 🙂 1.51% 👍
src/robotkernel/selectors.py 66.58% 🙂 66.61% 🙂 0.03% 👍
src/robotkernel/selectors_white.py 69.42% 🙂 69.50% 🙂 0.08% 👍
src/robotkernel/utils.py 63.40% 🙂 64.67% 🙂 1.27% 👍

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

File Function Complexity Length Working Memory Quality Recommendation
src/robotkernel/executors.py execute_python.run_robot_suite 22 😞 331 ⛔ 18 ⛔ 22.19% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
src/robotkernel/executors.py execute_python.process_screenshots 21 😞 273 ⛔ 16 ⛔ 26.62% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
src/robotkernel/selectors.py get_autoit_control_selector_completions 31 😞 212 ⛔ 13 😞 27.99% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
src/robotkernel/utils.py to_mime_and_metadata 24 😞 262 ⛔ 12 😞 30.50% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
src/robotkernel/selectors_white.py PickSnipTool.pick 15 🙂 214 ⛔ 12 😞 39.71% 😞 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!

Help us improve this quality report!

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.

0 participants