Skip to content

Conversation

@sourcery-ai
Copy link

@sourcery-ai sourcery-ai bot commented Mar 8, 2023

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 HighnessAtharva March 8, 2023 16:00
Copy link

@code-review-doctor code-review-doctor bot left a comment

Choose a reason for hiding this comment

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

Looks good. Worth considering though. View full project report here.

def sort_matrix(M):
result = sorted(M, key=lambda matrix_row: sum(matrix_row))
return result
return sorted(M, key=lambda matrix_row: sum(matrix_row))

Choose a reason for hiding this comment

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

Suggested change
return sorted(M, key=lambda matrix_row: sum(matrix_row))
return sorted(M, key=sum)

Avoid unnecessarily wrapping sum in a lambda. More details.

print(f.read())
f.close()

with open('exercises.txt', 'a') as f:

Choose a reason for hiding this comment

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

Suggested change
with open('exercises.txt', 'a') as f:
with open('exercises.txt', 'a', encoding='utf_8') as f:

UnicodeEncodeError can occur if the text being written to the file contain characters not compatible with the OS's default text encoding because encoding is not set. More info.

print(read_data)
print(f.closed)
f.close()
with open('exercises.txt') as f:

Choose a reason for hiding this comment

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

UnicodeDecodeError can occur if the content of the file has characters incompatible with the OS's default encoding. Python uses the OS's default text encoding on the content because encoding is not set. More details.

print(f.readline())
f.close()

with open('exercises.txt') as f:

Choose a reason for hiding this comment

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

Similarly, Set the encoding.

f1 = open('exercises.txt', 'a')
f1.write(f.read())
f.close()
with open('list-to-file.txt') as f:

Choose a reason for hiding this comment

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

Similarly, Set the encoding.

f1.write(f.read())
f.close()
with open('list-to-file.txt') as f:
f1 = open('exercises.txt', 'a')

Choose a reason for hiding this comment

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

Suggested change
f1 = open('exercises.txt', 'a')
f1 = open('exercises.txt', 'a', encoding='utf_8')

Same as above: Set the encoding.

for letter in string.ascii_uppercase:
with open(letter + ".txt", "w") as f:
f.writelines(letter)
with open(f"{letter}.txt", "w") as f:

Choose a reason for hiding this comment

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

Suggested change
with open(f"{letter}.txt", "w") as f:
with open(f"{letter}.txt", "w", encoding="utf_8") as f:

Same as above: Set the encoding.

f = open(filename, 'r')
text = f.read()
f.close()
with open(filename, 'r') as f:

Choose a reason for hiding this comment

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

UnicodeDecodeError can occur if the content of the file has characters incompatible with the OS's default encoding. Python uses the OS's default text encoding on the content because encoding is not set. More details.

print("{:<5}{:<15}: {:<90}: {}, {}\n ".format(str(i)+')',hacks_final_date, hacks_name.title(), hacks_city, hacks_country))

print(
"{:<5}{:<15}: {:<90}: {}, {}\n ".format(

Choose a reason for hiding this comment

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

f-string is easier to read, write, and less computationally expensive than legacy string formatting. Read more.

Co-authored-by: code-review-doctor[bot] <72320148+code-review-doctor[bot]@users.noreply.github.com>
@HighnessAtharva HighnessAtharva merged commit 7253402 into master Mar 8, 2023
@sourcery-ai
Copy link
Author

sourcery-ai bot commented Mar 8, 2023

Sourcery Code Quality Report

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

Quality metrics Before After Change
Complexity 13.79 🙂 13.15 🙂 -0.64 👍
Method Length 77.11 🙂 76.31 🙂 -0.80 👍
Working memory 7.63 🙂 7.66 🙂 0.03 👎
Quality 60.74% 🙂 60.92% 🙂 0.18% 👍
Other metrics Before After Change
Lines 16407 15997 -410
Changed files Quality Before Quality After Quality Change
Python/Basic Exercises I.py 55.89% 🙂 54.68% 🙂 -1.21% 👎
Python/Basic Exercises II.py 68.58% 🙂 69.27% 🙂 0.69% 👍
Python/BeautifulSoup4.py 39.20% 😞 39.20% 😞 0.00%
Python/CSV.py 39.60% 😞 39.61% 😞 0.01% 👍
Python/Classes.py 81.64% ⭐ 85.71% ⭐ 4.07% 👍
Python/Collections.py 62.10% 🙂 61.98% 🙂 -0.12% 👎
Python/DataStructures.py 16.61% ⛔ 19.54% ⛔ 2.93% 👍
Python/Datetime.py 64.09% 🙂 64.15% 🙂 0.06% 👍
Python/Enum&Bisect.py 62.09% 🙂 61.16% 🙂 -0.93% 👎
Python/FileIO.py 35.74% 😞 38.94% 😞 3.20% 👍
Python/Functions.py 93.54% ⭐ 95.02% ⭐ 1.48% 👍
Python/HeapQueue.py 70.40% 🙂 70.94% 🙂 0.54% 👍
Python/Itertools.py 84.91% ⭐ 84.91% ⭐ 0.00%
Python/JSON.py 54.27% 🙂 54.26% 🙂 -0.01% 👎
Python/Lambda.py 71.68% 🙂 72.89% 🙂 1.21% 👍
Python/LinkedList.py 89.36% ⭐ 89.42% ⭐ 0.06% 👍
Python/List.py 46.20% 😞 46.37% 😞 0.17% 👍
Python/LoopsAndConditionalStatements.py 18.15% ⛔ 17.64% ⛔ -0.51% 👎
Python/MapFunctions.py 81.04% ⭐ 80.62% ⭐ -0.42% 👎
Python/NLTK.py 30.09% 😞 30.09% 😞 0.00%
Python/NumpyArray.py 51.23% 🙂 51.14% 🙂 -0.09% 👎
Python/OperatingSystemServices.py 47.08% 😞 47.64% 😞 0.56% 👍
Python/Recursion.py 90.68% ⭐ 91.50% ⭐ 0.82% 👍
Python/RegularExpressions.py 27.48% 😞 27.48% 😞 0.00%
Python/SQLLiteDB.py 84.73% ⭐ 84.35% ⭐ -0.38% 👎
Python/Searching&Sorting.py 77.65% ⭐ 78.29% ⭐ 0.64% 👍
Python/Set.py 57.93% 🙂 61.61% 🙂 3.68% 👍
Python/Tuple.py 40.01% 😞 44.38% 😞 4.37% 👍
Python/WebScraping.py 52.39% 🙂 51.20% 🙂 -1.19% 👎
Python/modules.py 56.50% 🙂 58.12% 🙂 1.62% 👍

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

File Function Complexity Length Working Memory Quality Recommendation
Python/Itertools.py spermutations 29 😞 231 ⛔ 11 😞 31.05% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
Python/Enum&Bisect.py Solution.fourSum 14 🙂 178 😞 45.86% 😞 Try splitting into smaller methods
Python/Enum&Bisect.py Solution.threeSumClosest 15 🙂 165 😞 46.41% 😞 Try splitting into smaller methods
Python/Enum&Bisect.py Solution.three_Sum 19 😞 139 😞 10 😞 46.95% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
Python/HeapQueue.py Median_Finder.add_Number 16 🙂 217 ⛔ 7 🙂 48.94% 😞 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.

2 participants