From 4e759717ab018d065ff3b35943a27754b7741a27 Mon Sep 17 00:00:00 2001 From: Weves Date: Sat, 11 May 2024 12:34:29 -0700 Subject: [PATCH] Fix mypy --- .../connectors/danswer_jira/connector.py | 44 ++++++++++++------- .../danswer/connectors/notion/connector.py | 3 +- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/backend/danswer/connectors/danswer_jira/connector.py b/backend/danswer/connectors/danswer_jira/connector.py index 64923d1a6..212035901 100644 --- a/backend/danswer/connectors/danswer_jira/connector.py +++ b/backend/danswer/connectors/danswer_jira/connector.py @@ -44,38 +44,48 @@ def extract_jira_project(url: str) -> tuple[str, str]: return jira_base, jira_project -def extract_text_from_content(content): + +def extract_text_from_content(content: dict) -> str: texts = [] - if 'content' in content: - for block in content['content']: - if 'content' in block: - for item in block['content']: - if item['type'] == 'text': - texts.append(item['text']) + if "content" in content: + for block in content["content"]: + if "content" in block: + for item in block["content"]: + if item["type"] == "text": + texts.append(item["text"]) return " ".join(texts) -def _get_comment_strs(jira: Issue, comment_email_blacklist: tuple[str, ...] = ()) -> list[str]: + +def _get_comment_strs( + jira: Issue, comment_email_blacklist: tuple[str, ...] = () +) -> list[str]: comment_strs = [] for comment in jira.fields.comment.comments: try: - if hasattr(comment, 'body'): - body_text = extract_text_from_content(comment.raw['body']) - elif hasattr(comment, 'raw'): - body = comment.raw.get('body', 'No body content available') - body_text = extract_text_from_content(body) if isinstance(body, dict) else body + if hasattr(comment, "body"): + body_text = extract_text_from_content(comment.raw["body"]) + elif hasattr(comment, "raw"): + body = comment.raw.get("body", "No body content available") + body_text = ( + extract_text_from_content(body) if isinstance(body, dict) else body + ) else: body_text = "No body attribute found" - - if hasattr(comment, 'author') and comment.author.emailAddress in comment_email_blacklist: + + if ( + hasattr(comment, "author") + and comment.author.emailAddress in comment_email_blacklist + ): continue # Skip adding comment if author's email is in blacklist - + comment_strs.append(body_text) except Exception as e: logger.error(f"Failed to process comment due to an error: {e}") - continue + continue return comment_strs + def fetch_jira_issues_batch( jql: str, start_index: int, diff --git a/backend/danswer/connectors/notion/connector.py b/backend/danswer/connectors/notion/connector.py index 1b00f12e6..cadf10b32 100644 --- a/backend/danswer/connectors/notion/connector.py +++ b/backend/danswer/connectors/notion/connector.py @@ -231,7 +231,8 @@ class NotionConnector(LoadConnector, PollConnector): if result_type == "unsupported": logger.warning( - f"Skipping unsupported block type '{result_type}' ('{result_block_id}') for page '{page_block_id}': " + f"Skipping unsupported block type '{result_type}' " + f"('{result_block_id}') for base block '{base_block_id}': " f"(discussion: https://github.com/danswer-ai/danswer/issues/1230)" ) continue