Thanks to visit codestin.com
Credit goes to github.com

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 Apr 24, 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 edson-github April 24, 2022 14:44
for number in range(100):
# It just don't do anything but for loop is still valid.
pass
pass
Copy link
Author

Choose a reason for hiding this comment

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

Function test_pass_in_loop refactored with the following changes:

This removes the following comments ( why? ):

# It just don't do anything but for loop is still valid.

return 'Hello ' + self.name
return f'Hello {self.name}'
Copy link
Author

Choose a reason for hiding this comment

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

Function test_class_definition.GreetingClass.say_hello refactored with the following changes:

return 'Goodbye ' + self.name
return f'Goodbye {self.name}'
Copy link
Author

Choose a reason for hiding this comment

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

Function test_class_definition.GreetingClass.say_goodbye refactored with the following changes:

return self.get_name() + ', ' + self.staff_id
return f'{self.get_name()}, {self.staff_id}'
Copy link
Author

Choose a reason for hiding this comment

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

Function Employee.get_full_id refactored with the following changes:

for number in range(0, 10):
for number in range(10):
Copy link
Author

Choose a reason for hiding this comment

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

Function test_continue_statement refactored with the following changes:

Comment on lines 116 to -132

# 'Py' 'thon'
python = 'Py' 'thon'
assert python == 'Python'
Copy link
Author

Choose a reason for hiding this comment

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

Function test_string_operators refactored with the following changes:

This removes the following comments ( why? ):

# 'Py' 'thon'

Comment on lines -209 to +194
# To use formatted string literals, begin a string with f or F before the opening quotation
# mark or triple quotation mark. Inside this string, you can write a Python expression
# between { and } characters that can refer to variables or literal values.
year = 2018
event = 'conference'

assert f'Results of the {year} {event}' == 'Results of the 2018 conference'
assert f'Results of the 2018 {event}' == 'Results of the 2018 conference'
Copy link
Author

Choose a reason for hiding this comment

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

Function test_string_formatting refactored with the following changes:

This removes the following comments ( why? ):

# To use formatted string literals, begin a string with f or F before the opening quotation
# The String format() Method
# between { and } characters that can refer to variables or literal values.
# Basic usage of the str.format() method looks like this:
# mark or triple quotation mark. Inside this string, you can write a Python expression

fruits_tuple_via_constructor = tuple(("apple", "banana", "cherry"))
fruits_tuple_via_constructor = "apple", "banana", "cherry"
Copy link
Author

Choose a reason for hiding this comment

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

Function test_tuples refactored with the following changes:

@@ -23,7 +23,6 @@
def test_type_casting_to_integer():
"""Type casting to integer"""

assert int(1) == 1
Copy link
Author

Choose a reason for hiding this comment

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

Function test_type_casting_to_integer refactored with the following changes:

Comment on lines -35 to +34
assert float(2.8) == 2.8
assert 2.8 == 2.8
Copy link
Author

Choose a reason for hiding this comment

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

Function test_type_casting_to_float refactored with the following changes:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Apr 24, 2022

Sourcery Code Quality Report

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

Quality metrics Before After Change
Complexity 1.43 ⭐ 0.68 ⭐ -0.75 👍
Method Length 45.04 ⭐ 43.03 ⭐ -2.01 👍
Working memory 3.89 ⭐ 4.06 ⭐ 0.17 👎
Quality 80.29% 81.30% 1.01% 👍
Other metrics Before After Change
Lines 2140 2023 -117
Changed files Quality Before Quality After Quality Change
src/additions/test_pass.py 99.57% ⭐ 100.00% ⭐ 0.43% 👍
src/classes/test_class_definition.py 96.11% ⭐ 95.83% ⭐ -0.28% 👎
src/classes/test_inheritance.py 92.15% ⭐ 92.14% ⭐ -0.01% 👎
src/control_flow/test_continue.py 82.42% ⭐ 82.58% ⭐ 0.16% 👍
src/control_flow/test_for.py 58.71% 🙂 60.47% 🙂 1.76% 👍
src/control_flow/test_while.py 93.51% ⭐ 96.67% ⭐ 3.16% 👍
src/data_types/test_lists.py 68.47% 🙂 71.47% 🙂 3.00% 👍
src/data_types/test_numbers.py 90.81% ⭐ 91.37% ⭐ 0.56% 👍
src/data_types/test_sets.py 81.79% ⭐ 81.86% ⭐ 0.07% 👍
src/data_types/test_strings.py 73.08% 🙂 72.80% 🙂 -0.28% 👎
src/data_types/test_tuples.py 75.30% ⭐ 75.77% ⭐ 0.47% 👍
src/data_types/test_type_casting.py 97.62% ⭐ 98.25% ⭐ 0.63% 👍
src/exceptions/test_handle_exceptions.py 71.63% 🙂 72.98% 🙂 1.35% 👍
src/files/test_file_methods.py 85.69% ⭐ 86.13% ⭐ 0.44% 👍
src/files/test_file_reading.py 93.58% ⭐ 94.06% ⭐ 0.48% 👍
src/functions/test_function_annotations.py 98.00% ⭐ 97.92% ⭐ -0.08% 👎
src/functions/test_function_definition.py 88.99% ⭐ 88.89% ⭐ -0.10% 👎
src/functions/test_function_keyword_arguments.py 81.66% ⭐ 81.66% ⭐ 0.00%
src/functions/test_function_scopes.py 95.79% ⭐ 96.03% ⭐ 0.24% 👍
src/functions/test_function_unpacking_arguments.py 90.83% ⭐ 90.83% ⭐ 0.00%
src/getting_started/test_variables.py 97.01% ⭐ 100.00% ⭐ 2.99% 👍
src/operators/test_arithmetic.py 82.94% ⭐ 86.07% ⭐ 3.13% 👍
src/operators/test_assigment.py 84.06% ⭐ 84.36% ⭐ 0.30% 👍
src/operators/test_identity.py 96.84% ⭐ 96.84% ⭐ 0.00%
src/operators/test_logical.py 91.20% ⭐ 91.36% ⭐ 0.16% 👍

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

File Function Complexity Length Working Memory Quality Recommendation
src/control_flow/test_for.py test_for_statement 5 ⭐ 228 ⛔ 8 🙂 55.81% 🙂 Try splitting into smaller methods
src/data_types/test_lists.py test_list_comprehensions 1 ⭐ 336 ⛔ 6 ⭐ 60.28% 🙂 Try splitting into smaller methods
src/data_types/test_strings.py test_string_formatting 0 ⭐ 198 😞 8 🙂 62.83% 🙂 Try splitting into smaller methods
src/data_types/test_lists.py test_list_type 0 ⭐ 226 ⛔ 4 ⭐ 70.90% 🙂 Try splitting into smaller methods
src/data_types/test_lists.py test_nested_list_comprehensions 1 ⭐ 159 😞 5 ⭐ 72.64% 🙂 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!

assert float("3") == 3.0
assert float("4.2") == 4.2


def test_type_casting_to_string():
"""Type casting to string"""

assert str("s1") == 's1'
Copy link
Author

Choose a reason for hiding this comment

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

Function test_type_casting_to_string refactored with the following changes:

Comment on lines -79 to -85
except NameError:
except (NameError, ZeroDivisionError):
# We should get here because of division by zero.
exception_has_been_handled = True
except ZeroDivisionError:
# We should get here because of division by zero.
exception_has_been_handled = True

Copy link
Author

Choose a reason for hiding this comment

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

Function test_handle_exceptions refactored with the following changes:

Comment on lines -14 to +48
binary_file = open('src/files/binary_file', 'r')

# To read a file’s contents, call f.read(size), which reads some quantity of data and returns
# it as a string (in text mode) or bytes object (in binary mode). size is an optional numeric
# argument. When size is omitted or negative, the entire contents of the file will be read and
# returned; it’s your problem if the file is twice as large as your machine’s memory. Otherwise,
# at most size bytes are read and returned. If the end of the file has been reached, f.read()
# will return an empty string ('').
read_data = multi_line_file.read()

# pylint: disable=duplicate-code
assert read_data == 'first line\nsecond line\nthird line'

# To change the file object’s position, use f.seek(offset, from_what). The position is computed
# from adding offset to a reference point; the reference point is selected by the from_what
# argument. A from_what value of 0 measures from the beginning of the file, 1 uses the current
# file position, and 2 uses the end of the file as the reference point. from_what can be omitted
# and defaults to 0, using the beginning of the file as the reference point.
assert binary_file.seek(0) == 0 # Go to the 0th byte in the file
assert binary_file.seek(6) == 6 # Go to the 6th byte in the file

assert binary_file.read(1) == '6'

# f.readline() reads a single line from the file; a newline character (\n) is left at the end
# of the string, and is only omitted on the last line of the file if the file doesn’t end in a
# newline. This makes the return value unambiguous; if f.readline() returns an empty string,
# the end of the file has been reached, while a blank line is represented by '\n', a string
# containing only a single newline.
multi_line_file.seek(0)

assert multi_line_file.readline() == 'first line\n'
assert multi_line_file.readline() == 'second line\n'
assert multi_line_file.readline() == 'third line'
assert multi_line_file.readline() == ''

multi_line_file.close()
binary_file.close()
with open('src/files/binary_file', 'r') as binary_file:
# To read a file’s contents, call f.read(size), which reads some quantity of data and returns
# it as a string (in text mode) or bytes object (in binary mode). size is an optional numeric
# argument. When size is omitted or negative, the entire contents of the file will be read and
# returned; it’s your problem if the file is twice as large as your machine’s memory. Otherwise,
# at most size bytes are read and returned. If the end of the file has been reached, f.read()
# will return an empty string ('').
read_data = multi_line_file.read()

# pylint: disable=duplicate-code
assert read_data == 'first line\nsecond line\nthird line'

# To change the file object’s position, use f.seek(offset, from_what). The position is computed
# from adding offset to a reference point; the reference point is selected by the from_what
# argument. A from_what value of 0 measures from the beginning of the file, 1 uses the current
# file position, and 2 uses the end of the file as the reference point. from_what can be omitted
# and defaults to 0, using the beginning of the file as the reference point.
assert binary_file.seek(0) == 0 # Go to the 0th byte in the file
assert binary_file.seek(6) == 6 # Go to the 6th byte in the file

assert binary_file.read(1) == '6'

# f.readline() reads a single line from the file; a newline character (\n) is left at the end
# of the string, and is only omitted on the last line of the file if the file doesn’t end in a
# newline. This makes the return value unambiguous; if f.readline() returns an empty string,
# the end of the file has been reached, while a blank line is represented by '\n', a string
# containing only a single newline.
multi_line_file.seek(0)

assert multi_line_file.readline() == 'first line\n'
assert multi_line_file.readline() == 'second line\n'
assert multi_line_file.readline() == 'third line'
assert multi_line_file.readline() == ''

multi_line_file.close()
Copy link
Author

Choose a reason for hiding this comment

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

Function test_file_methods refactored with the following changes:

Comment on lines -44 to +53
# Open files without using 'with' statement.
file = open('src/files/multi_line_file.txt', 'r')

assert not file.closed

read_data = file.read()
with open('src/files/multi_line_file.txt', 'r') as file:
assert not file.closed

assert read_data == (
'first line\n'
'second line\n'
'third line'
)
read_data = file.read()

file.close()
assert read_data == (
'first line\n'
'second line\n'
'third line'
)
Copy link
Author

Choose a reason for hiding this comment

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

Function test_files_open refactored with the following changes:

This removes the following comments ( why? ):

# Open files without using 'with' statement.

return ham + ' and ' + eggs
return f'{ham} and {eggs}'
Copy link
Author

Choose a reason for hiding this comment

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

Function breakfast refactored with the following changes:

Comment on lines -12 to +16
# Addition.
assert 5 + 3 == 8

# Subtraction.
assert 5 - 3 == 2

# Multiplication.
assert 5 * 3 == 15
assert isinstance(5 * 3, int)

# Division.
# Result of division is float number.
assert 5 / 3 == 1.6666666666666667
assert 8 / 4 == 2
assert 5 == 1.6666666666666667 * 3
Copy link
Author

Choose a reason for hiding this comment

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

Function test_arithmetic_operators refactored with the following changes:

This removes the following comments ( why? ):

# Subtraction.
# Multiplication.
# Addition.

Comment on lines 11 to -14

# Assignment: =
number = 5
assert number == 5
Copy link
Author

Choose a reason for hiding this comment

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

Function test_assignment_operator refactored with the following changes:

This removes the following comments ( why? ):

# Assignment: =

Comment on lines -31 to +36
# Assignment: +=
number = 5
number += 3
number = 5 + 3
assert number == 8

# Assignment: -=
number = 5
number -= 3
number = 5 - 3
assert number == 2

# Assignment: *=
number = 5
number *= 3
number = 5 * 3
assert number == 15

# Assignment: /=
number = 8
number /= 4
number = 8 / 4
Copy link
Author

Choose a reason for hiding this comment

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

Function test_augmented_assignment_operators refactored with the following changes:

This removes the following comments ( why? ):

# Assignment: -=
# Assignment: /=
# Assignment: +=
# Assignment: *=

Comment on lines -18 to +20
# is
# Returns true if both variables are the same object.

# Example:
# first_fruits_list and third_fruits_list are the same objects.
assert first_fruits_list is third_fruits_list

# is not
# Returns true if both variables are not the same object.

# Example:
# first_fruits_list and second_fruits_list are not the same objects, even if they have
# the same content
assert first_fruits_list is not second_fruits_list

# To demonstrate the difference between "is" and "==": this comparison returns True because
# first_fruits_list is equal to second_fruits_list.
assert first_fruits_list == second_fruits_list
assert third_fruits_list is third_fruits_list
assert third_fruits_list is not second_fruits_list
assert third_fruits_list == second_fruits_list
Copy link
Author

Choose a reason for hiding this comment

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

Function test_identity_operators refactored with the following changes:

This removes the following comments ( why? ):

# Returns true if both variables are the same object.
# is not
# To demonstrate the difference between "is" and "==": this comparison returns True because
# is
# first_fruits_list and second_fruits_list are not the same objects, even if they have
# first_fruits_list is equal to second_fruits_list.
# Example:
# the same content
# first_fruits_list and third_fruits_list are the same objects.
# Returns true if both variables are not the same object.

Comment on lines -27 to 28
assert not first_number == second_number
assert first_number != second_number
assert first_number != second_number
Copy link
Author

Choose a reason for hiding this comment

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

Function test_logical_operators refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

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