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 Starbot ⭐ refactored evgenytsydenov/python_course #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

SourceryAI
Copy link

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:

git fetch https://github.com/sourcery-ai-bot/python_course main
git merge --ff-only FETCH_HEAD
git reset HEAD^

Comment on lines -250 to +251
match = re.search('.*<(?P<email>.*)>.*', sender)
if match:
sender = match.group('email')
if match := re.search('.*<(?P<email>.*)>.*', sender):
sender = match['email']
Copy link
Author

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:

Comment on lines -268 to +270
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 = ''
Copy link
Author

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:

Comment on lines -384 to +397
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()
Copy link
Author

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)

Comment on lines -411 to +432
.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()
Copy link
Author

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)

Comment on lines -78 to +80
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)
Copy link
Author

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:

Comment on lines -99 to +109
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)
Copy link
Author

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:

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]:
Copy link
Author

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:

Comment on lines -321 to +320
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('#')
)
Copy link
Author

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:

if datefmt:
return dt.strftime(datefmt)
return dt.isoformat()
return dt.strftime(datefmt) if datefmt else dt.isoformat()
Copy link
Author

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:

Comment on lines -61 to +63
f'Content-Disposition',
f'attachment; filename="{file_name}"')
'Content-Disposition',
f'attachment; filename="{file_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 SMTPSender.send refactored with the following changes:

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.

1 participant