Skip to content

Commit

Permalink
fix: try002 for provider imap (#38804)
Browse files Browse the repository at this point in the history
  • Loading branch information
dondaum committed Apr 9, 2024
1 parent ca501ef commit d7e7056
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
6 changes: 3 additions & 3 deletions airflow/providers/imap/hooks/imap.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def _retrieve_mails_attachments_by_name(
self, name: str, check_regex: bool, latest_only: bool, mail_folder: str, mail_filter: str
) -> list:
if not self.mail_client:
raise Exception("The 'mail_client' should be initialized before!")
raise RuntimeError("The 'mail_client' should be initialized before!")

all_matching_attachments = []

Expand All @@ -240,14 +240,14 @@ def _retrieve_mails_attachments_by_name(

def _list_mail_ids_desc(self, mail_filter: str) -> Iterable[str]:
if not self.mail_client:
raise Exception("The 'mail_client' should be initialized before!")
raise RuntimeError("The 'mail_client' should be initialized before!")
_, data = self.mail_client.search(None, mail_filter)
mail_ids = data[0].split()
return reversed(mail_ids)

def _fetch_mail_body(self, mail_id: str) -> str:
if not self.mail_client:
raise Exception("The 'mail_client' should be initialized before!")
raise RuntimeError("The 'mail_client' should be initialized before!")
_, data = self.mail_client.fetch(mail_id, "(RFC822)")
mail_body = data[0][1] # type: ignore # The mail body is always in this specific location
mail_body_str = mail_body.decode("utf-8") # type: ignore
Expand Down
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,6 @@ combine-as-imports = true
# All the providers modules which do not follow TRY002 yet
# cncf.kubernetes
"airflow/providers/cncf/kubernetes/operators/pod.py" = ["TRY002"]
# imap
"airflow/providers/imap/hooks/imap.py" = ["TRY002"]

[tool.ruff.lint.flake8-tidy-imports]
# Disallow all relative imports.
Expand Down

0 comments on commit d7e7056

Please sign in to comment.