-
-
Notifications
You must be signed in to change notification settings - Fork 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
Sourcery Starbot ⭐ refactored evgenytsydenov/python_course #1
base: main
Are you sure you want to change the base?
Conversation
match = re.search('.*<(?P<email>.*)>.*', sender) | ||
if match: | ||
sender = match.group('email') | ||
if match := re.search('.*<(?P<email>.*)>.*', sender): | ||
sender = match['email'] |
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 GmailExchanger._extract_email
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
) - Replace m.group(x) with m[x] for re.Match objects (
use-getitem-for-re-match-groups
)
match = re.search('^(?P<label>.*)/(?P<lesson>.*)$', subject) | ||
les_name = '' | ||
if match: | ||
les_name = match.group('lesson') | ||
if match := re.search('^(?P<label>.*)/(?P<lesson>.*)$', subject): | ||
les_name = match['lesson'] | ||
else: | ||
les_name = '' |
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 GmailExchanger._extract_lesson_name
refactored with the following changes:
- Move setting of default value for variable into
else
branch (introduce-default-else
) - Replace m.group(x) with m[x] for re.Match objects (
use-getitem-for-re-match-groups
) - Use named expression to simplify assignment and conditional (
use-named-expression
)
label_info = {} | ||
for label in all_labels['labels']: | ||
if label['name'] == label_name: | ||
label_info = label | ||
break | ||
label_info = next( | ||
( | ||
label | ||
for label in all_labels['labels'] | ||
if label['name'] == label_name | ||
), | ||
{}, | ||
) | ||
if label_info: | ||
logger.debug(f'Gmail label "{label_info}" already exists.') | ||
else: | ||
body = {'name': label_name, 'messageListVisibility': 'show', | ||
'labelListVisibility': 'labelShow'} | ||
label_info = self._gmail.users().labels() \ | ||
.create(userId='me', body=body).execute() | ||
.create(userId='me', body=body).execute() |
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 GmailExchanger._get_label_id
refactored with the following changes:
- Use the built-in function
next
instead of a for-loop (use-next
)
.list(userId='me').execute() | ||
.list(userId='me').execute() | ||
|
||
# Find if already exist | ||
criteria = {'to': fetch_alias, 'subject': fetch_keyword} | ||
action = {'addLabelIds': [label_id], | ||
'removeLabelIds': ['INBOX', 'SPAM']} | ||
filter_info = {} | ||
for gmail_filter in filters['filter']: | ||
if (gmail_filter['criteria'] == criteria) \ | ||
and (gmail_filter['action'] == action): | ||
filter_info = gmail_filter | ||
break | ||
|
||
if filter_info: | ||
if filter_info := next( | ||
( | ||
gmail_filter | ||
for gmail_filter in filters['filter'] | ||
if (gmail_filter['criteria'] == criteria) | ||
and (gmail_filter['action'] == action) | ||
), | ||
{}, | ||
): | ||
logger.debug(f'Filter {filter_info} already exists.') | ||
else: | ||
body = {'criteria': criteria, 'action': action} | ||
self._gmail.users().settings().filters() \ | ||
.create(userId='me', body=body).execute() | ||
.create(userId='me', body=body).execute() |
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 GmailExchanger._create_filter
refactored with the following changes:
- Use the built-in function
next
instead of a for-loop (use-next
) - Use named expression to simplify assignment and conditional (
use-named-expression
)
f'/ {timestamp}' | ||
score = sum([task.score for task in grade_result.task_grades]) | ||
max_score = sum([task.max_score for task in grade_result.task_grades]) | ||
f'/ {timestamp}' | ||
score = sum(task.score for task in grade_result.task_grades) | ||
max_score = sum(task.max_score for task in grade_result.task_grades) |
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 FeedbackCreator._get_success_feedback
refactored with the following changes:
- Replace unneeded comprehension with generator [×2] (
comprehension-to-generator
)
f"and trashed != True" | ||
cloud_file = self._find_cloud_files(query, ['id']) | ||
if not cloud_file: | ||
logger.debug(f'File or folder "{local_name}" does not exist ' | ||
f'in the cloud path "{cloud_folder_path}".') | ||
cloud_file_id = self._upload_file(local_file, parent_id) | ||
else: | ||
f"and trashed != True" | ||
if cloud_file := self._find_cloud_files(query, ['id']): | ||
cloud_file_id = cloud_file[0]['id'] | ||
logger.debug(f'File or folder "{local_name}" exists ' | ||
f'in the cloud path "{cloud_folder_path}".') | ||
self._update_cloud_file(cloud_file_id, local_file) | ||
else: | ||
logger.debug(f'File or folder "{local_name}" does not exist ' | ||
f'in the cloud path "{cloud_folder_path}".') | ||
cloud_file_id = self._upload_file(local_file, parent_id) |
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 GDrivePublisher.sync
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
) - Swap if/else branches (
swap-if-else-branches
) - Use any() instead of for loop (
use-any
)
def _get_cloud_file(self, file_id: str, attributes: Iterable[str]) \ | ||
-> Dict[str, Any]: | ||
def _get_cloud_file(self, file_id: str, attributes: Iterable[str]) -> Dict[str, Any]: |
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 GDrivePublisher._get_cloud_file
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
for line in file.readlines(): | ||
if line.strip() and not line.startswith('#'): | ||
patterns.append(line) | ||
patterns.extend( | ||
line for line in file if line.strip() and not line.startswith('#') | ||
) |
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 GDrivePublisher._get_ignore_files
refactored with the following changes:
- Iterate over files directly rather than using readlines() (
use-file-iterator
) - Replace a for append loop with list extend (
for-append-to-extend
)
if datefmt: | ||
return dt.strftime(datefmt) | ||
return dt.isoformat() | ||
return dt.strftime(datefmt) if datefmt else dt.isoformat() |
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 CustomFormatter.formatTime
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
)
f'Content-Disposition', | ||
f'attachment; filename="{file_name}"') | ||
'Content-Disposition', | ||
f'attachment; filename="{file_name}"', | ||
) |
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 SMTPSender.send
refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
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
main
branch, then run: