-
Notifications
You must be signed in to change notification settings - Fork 1
Sourcery Starbot ⭐ refactored gkitg/edu_tmp #1
10000 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
base: master
Are you sure you want to change the base?
Conversation
|
||
# длинный способ | ||
if year % 4 != 0: | ||
print("Обычный") | ||
elif year % 100 == 0: | ||
if year % 400 == 0: | ||
print("Високосный") | ||
else: | ||
print("Обычный") | ||
if ( | ||
year % 4 == 0 | ||
and year % 100 == 0 | ||
and year % 400 == 0 | ||
or year % 4 == 0 | ||
and year % 100 != 0 | ||
): | ||
print("Високосный") | ||
else: | ||
print("Високосный") No newline at end of file | ||
print("Обычный") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 15-25
refactored with the following changes:
- Merge duplicate blocks in conditional (
merge-duplicate-blocks
)
num = num // 10 | ||
num //= 10 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 17-17
refactored with the following changes:
- Replace assignment with augmented assignment (
aug-assign
)
num = num // 10 | ||
num //= 10 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 14-14
refactored with the following changes:
- Replace assignment with augmented assignment (
aug-assign
)
if n == 1: | ||
return n | ||
sum_n = n + sum_natural(n - 1) | ||
return sum_n | ||
return n if n == 1 else n + sum_natural(n - 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function sum_natural
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
) - Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
if number < 10: | ||
return number | ||
return number % 10 + sum_digits(number // 10) | ||
return number if number < 10 else number % 10 + sum_digits(number // 10) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function sum_digits
refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
x = "".join([i for i in x]) | ||
y = "".join([i for i in y]) | ||
x = "".join(list(x)) | ||
y = "".join(list(y)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function hex_sum
refactored with the following changes:
- Replace identity comprehension with call to collection constructor [×2] (
identity-comprehension
)
x = "".join([i for i in x]) | ||
y = "".join([i for i in y]) | ||
x = "".join(list(x)) | ||
y = "".join(list(y)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function hex_mul
refactored with the following changes:
- Replace identity comprehension with call to collection constructor [×2] (
identity-comprehension
)
else: | ||
r = deque() | ||
while x > 15: | ||
d = x % 16 | ||
r.appendleft(str(d) if d < 10 else self.hex_letters._fields[d-10]) | ||
x = x // 16 | ||
r.appendleft(str(x) if x < 10 else self.hex_letters._fields[x-10]) | ||
return list(r) | ||
r = deque() | ||
while x > 15: | ||
d = x % 16 | ||
r.appendleft(str(d) if d < 10 else self.hex_letters._fields[d-10]) | ||
x = x // 16 | ||
r.appendleft(str(x) if x < 10 else self.hex_letters._fields[x-10]) | ||
return list(r) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function HexCalc.to_hex
refactored with the following changes:
- Remove unnecessary else after guard condition (
remove-unnecessary-else
)
return sum([hex_number[j] * (16 ** i) for i, j in enumerate(num)]) | ||
return sum(hex_number[j] * (16 ** i) for i, j in enumerate(num)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function hex_to_decimal
refactored with the following changes:
- Replace unneeded comprehension with generator (
comprehension-to-generator
)
for key in pi_func.keys(): | ||
for key, size in pi_func.items(): | ||
if num <= key: | ||
size = pi_func[key] | ||
break | ||
|
||
array = [i for i in range(size)] | ||
array = list(range(size)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function prime
refactored with the following changes:
- Use items() to directly unpack dictionary values (
use-dict-items
) - Remove unnecessary call to keys() (
remove-dict-keys
) - Replace identity comprehension with call to collection constructor (
identity-comprehension
)
for i in range(num): | ||
for _ in range(num): | ||
name = input('name = ') | ||
spam = [] | ||
for j in range(1, 5): | ||
spam.append(int(input(f'{j} = '))) | ||
spam = [int(input(f'{j} = ')) for j in range(1, 5)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 7-11
refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore
) - Convert for loop into list comprehension (
list-comprehension
)
num = num // 10 | ||
num //= 10 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 15-32
refactored with the following changes:
- Replace assignment with augmented assignment [×2] (
aug-assign
)
orig_list = [random.randint(-100, 100) for i in range(10)] | ||
orig_list = [random.randint(-100, 100) for _ in range(10)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 40-40
refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore
)
if len(alist)>1: | ||
mid = len(alist)//2 | ||
lefthalf = alist[:mid] | ||
righthalf = alist[mid:] | ||
|
||
merge_sort(lefthalf) | ||
merge_sort(righthalf) | ||
|
||
i=0 | ||
j=0 | ||
k=0 | ||
while i<len(lefthalf) and j<len(righthalf): | ||
if lefthalf[i]<righthalf[j]: | ||
alist[k]=lefthalf[i] | ||
i=i+1 | ||
else: | ||
alist[k]=righthalf[j] | ||
j=j+1 | ||
k=k+1 | ||
|
||
while i<len(lefthalf): | ||
if len(alist) <= 1: | ||
return | ||
mid = len(alist)//2 | ||
lefthalf = alist[:mid] | ||
righthalf = alist[mid:] | ||
|
||
merge_sort(lefthalf) | ||
merge_sort(righthalf) | ||
|
||
i=0 | ||
j=0 | ||
k=0 | ||
while i<len(lefthalf) and j<len(righthalf): | ||
if lefthalf[i]<righthalf[j]: | ||
alist[k]=lefthalf[i] | ||
i=i+1 | ||
k=k+1 | ||
|
||
while j<len(righthalf): | ||
i += 1 | ||
else: | ||
alist[k]=righthalf[j] | ||
j=j+1 | ||
k=k+1 | ||
j += 1 | ||
k=k+1 | ||
|
||
while i<len(lefthalf): | ||
alist[k]=lefthalf[i] | ||
i += 1 | ||
k=k+1 | ||
|
||
while j<len(righthalf): | ||
alist[k]=righthalf[j] | ||
j += 1 | ||
k=k+1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function merge_sort
refactored with the following changes:
- Add guard clause (
last-if-guard
) - Replace assignment with augmented assignment [×4] (
aug-assign
)
alist = [random.random()*50 for i in range(n)] | ||
alist = [random.random()*50 for _ in range(n)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 43-43
refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore
)
if any(i.isupper() for i in data) and any(i.islower() for i in data) and any(i.isdigit() for i in data): | ||
return True | ||
else: | ||
return False | ||
return ( | ||
any(i.isupper() for i in data) | ||
and any(i.islower() for i in data) | ||
and any(i.isdigit() for i in data) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function checkio
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
) - Simplify boolean if expression (
boolean-if-exp-identity
) - Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
)
newlst=[] | ||
for i in data: | ||
if data.count(i)>1: | ||
newlst.append(i) | ||
return newlst | ||
return [i for i in data if data.count(i)>1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function checkio
refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
assert list(checkio([1, 2, 3, 4, 5])) == [], "2nd example" | ||
assert not list(checkio([1, 2, 3, 4, 5])), "2nd example" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 67-67
refactored with the following changes:
- Replaces an empty collection equality with a boolean operation (
simplify-empty-collection-comparison
)
segment = (((x1 - x2) ** 2) + ((y1 - y2) ** 2)) ** 0.5 | ||
return segment | ||
return (((x1 - x2) ** 2) + ((y1 - y2) ** 2)) ** 0.5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function length_segment
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
elif (line_a[0] == line_b[0] and (line_a[0] != line_c[0] or line_b[0] != line_c[0])): | ||
elif line_a[0] == line_b[0]: | ||
print("a || b") | ||
print(0) | ||
elif (line_a[0] == line_c[0] and (line_a[0] != line_b[0] or line_c[0] != line_b[0])): | ||
elif line_a[0] == line_c[0]: | ||
print("a || с") | ||
print(0) | ||
elif (line_b[0] == line_c[0] and (line_b[0] != line_a[0] or line_c[0] != line_a[0])): | ||
elif line_b[0] == line_c[0]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function run
refactored with the following changes:
- Remove redundant conditional [×3] (
remove-redundant-if
)
Thanks for starring sourcery-ai/sourcery ✨ 🌟 ✨
Here's your pull request refactoring your most popular Python repo.
If you want Sourcery to refactor all your Python repos and incoming pull requests install our bot.
Review changes via command line
To manually merge these changes, make sure you're on the
master
branch, then run: