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

Sourcery refactored master branch #1

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 Mar 18, 2022

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!

@sourcery-ai sourcery-ai bot requested a review from NoorXd786 March 18, 2022 04:20
copyright = str(datetime.date.today().year) + ', SuHun Han (ssut)'
copyright = f'{str(datetime.date.today().year)}, SuHun Han (ssut)'
Copy link
Author

Choose a reason for hiding this comment

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

Lines 59-59 refactored with the following changes:

for t in enumerate(service_urls):
for _ in enumerate(service_urls):
Copy link
Author

Choose a reason for hiding this comment

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

Function Translator.__init__ refactored with the following changes:

Comment on lines -136 to +139
extra = {}

for index, category in response_parts_name_mapping.items():
extra[category] = data[index] if (
index < len(data) and data[index]) else None

return extra
return {
category: data[index] if (index < len(data) and data[index]) else None
for index, category in response_parts_name_mapping.items()
}
Copy link
Author

Choose a reason for hiding this comment

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

Function Translator._parse_extra_data refactored with the following changes:

Comment on lines -213 to +210
translated = ''.join([d[0] if d[0] else '' for d in data[0]])
translated = ''.join([d[0] or '' for d in data[0]])
Copy link
Author

Choose a reason for hiding this comment

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

Function Translator.translate refactored with the following changes:

self.host = host if 'http' in host else 'https://' + host
self.host = host if 'http' in host else f'https://{host}'
Copy link
Author

Choose a reason for hiding this comment

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

Function TokenAcquirer.__init__ refactored with the following changes:

raw_tkk = self.RE_TKK.search(r.text)
if raw_tkk:
if raw_tkk := self.RE_TKK.search(r.text):
Copy link
Author

Choose a reason for hiding this comment

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

Function TokenAcquirer._update refactored with the following changes:

d = rshift(a, d) if '+' == b[c + 1] else a << d
a = a + d & 4294967295 if '+' == b[c] else a ^ d
d = rshift(a, d) if b[c + 1] == '+' else a << d
a = a + d & 4294967295 if b[c] == '+' else a ^ d
Copy link
Author

Choose a reason for hiding this comment

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

Function TokenAcquirer._xr refactored with the following changes:

@@ -166,7 +165,6 @@ def acquire(self, text):
# just append if l is less than 128(ascii: DEL)
if l < 128:
e.append(l)
# append calculated value if l is less than 2048
Copy link
Author

Choose a reason for hiding this comment

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

Function TokenAcquirer.acquire refactored with the following changes:

This removes the following comments ( why? ):

# append calculated value if l is less than 2048

Comment on lines -200 to +197
tk = self.acquire(text)
return tk
return self.acquire(text)
Copy link
Author

Choose a reason for hiding this comment

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

Function TokenAcquirer.do refactored with the following changes:

converted = json.loads(text)
return converted
return json.loads(text)
Copy link
Author

Choose a reason for hiding this comment

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

Function legacy_format_json refactored with the following changes:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Mar 18, 2022

Sourcery Code Quality Report

❌  Merging this PR will decrease code quality in the affected files by 0.09%.

Quality metrics Before After Change
Complexity 14.02 🙂 14.07 🙂 0.05 👎
Method Length 85.05 🙂 84.14 🙂 -0.91 👍
Working memory 11.71 😞 11.62 😞 -0.09 👍
Quality 49.79% 😞 49.70% 😞 -0.09% 👎
Other metrics Before After Change
Lines 783 775 -8
Changed files Quality Before Quality After Quality Change
docs/conf.py 71.31% 🙂 71.20% 🙂 -0.11% 👎
googletrans/client.py 52.50% 🙂 51.76% 🙂 -0.74% 👎
googletrans/gtoken.py 32.65% 😞 32.78% 😞 0.13% 👍
googletrans/utils.py 71.63% 🙂 72.21% 🙂 0.58% 👍

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

File Function Complexity Length Working Memory Quality Recommendation
googletrans/gtoken.py TokenAcquirer._update 35 ⛔ 286 ⛔ 18 ⛔ 16.79% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
googletrans/gtoken.py TokenAcquirer.acquire 23 😞 267 ⛔ 17 ⛔ 24.55% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
googletrans/client.py Translator.translate 22 😞 227 ⛔ 13 😞 32.09% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
googletrans/client.py Translator.__init__ 9 🙂 128 😞 12 😞 52.99% 🙂 Try splitting into smaller methods. Extract out complex expressions
googletrans/utils.py legacy_format_json 8 ⭐ 140 😞 9 🙂 58.22% 🙂 Try splitting into smaller methods

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