style: Apply ruff auto-fixes for Python 3.12

- Update type annotations to modern syntax (dict, list, X | Y)
- Remove unnecessary elif after return
- Minor style improvements

Note: Some linting warnings remain (unused content param, inline conditions)
but these are minor style issues and do not affect functionality.
All tests pass with these changes.
This commit is contained in:
Bendt
2025-12-28 10:55:31 -05:00
parent 78ab945a4d
commit b1cd99abf2
3 changed files with 94 additions and 33 deletions

View File

@@ -1,13 +1,12 @@
"""Notification email compressor for terminal-friendly display."""
from typing import Dict, Any, Optional
from textual.widgets import Markdown
from typing import Any
from .notification_detector import (
is_notification_email,
NotificationType,
classify_notification,
extract_notification_summary,
NotificationType,
is_notification_email,
)
@@ -22,7 +21,7 @@ class NotificationCompressor:
"""
self.mode = mode
def should_compress(self, envelope: Dict[str, Any]) -> bool:
def should_compress(self, envelope: dict[str, Any]) -> bool:
"""Check if email should be compressed.
Args:
@@ -37,8 +36,8 @@ class NotificationCompressor:
return is_notification_email(envelope)
def compress(
self, content: str, envelope: Dict[str, Any]
) -> tuple[str, Optional[NotificationType]]:
self, content: str, envelope: dict[str, Any]
) -> tuple[str, NotificationType | None]:
"""Compress notification email content.
Args:
@@ -65,9 +64,9 @@ class NotificationCompressor:
def _format_as_markdown(
self,
summary: Dict[str, Any],
envelope: Dict[str, Any],
notif_type: Optional[NotificationType],
summary: dict[str, Any],
envelope: dict[str, Any],
notif_type: NotificationType | None,
) -> str:
"""Format summary as markdown for terminal display.
@@ -138,9 +137,9 @@ class DetailedCompressor(NotificationCompressor):
def _format_as_markdown(
self,
summary: Dict[str, Any],
envelope: Dict[str, Any],
notif_type: Optional[NotificationType],
summary: dict[str, Any],
envelope: dict[str, Any],
notif_type: NotificationType | None,
) -> str:
"""Format summary with more detail."""
@@ -217,5 +216,4 @@ def create_compressor(mode: str) -> NotificationCompressor:
if mode == "detailed":
return DetailedCompressor(mode=mode)
else:
return NotificationCompressor(mode=mode)
return NotificationCompressor(mode=mode)

View File

@@ -1,8 +1,8 @@
"""Email notification detection utilities."""
import re
from typing import Dict, Any, List, Optional
from dataclasses import dataclass
from typing import Any
@dataclass
@@ -10,11 +10,11 @@ class NotificationType:
"""Classification of notification email types."""
name: str
patterns: List[str]
domains: List[str]
patterns: list[str]
domains: list[str]
icon: str
def matches(self, envelope: Dict[str, Any], content: Optional[str] = None) -> bool:
def matches(self, envelope: dict[str, Any], content: str | None = None) -> bool:
"""Check if envelope matches this notification type."""
# Check sender domain (more specific check)
@@ -24,7 +24,7 @@ class NotificationType:
if domain == "atlassian.net":
if "jira@" in from_addr:
return self.name == "jira"
elif "confluence@" in from_addr:
if "confluence@" in from_addr:
return self.name == "confluence"
elif domain in from_addr:
return True
@@ -85,7 +85,7 @@ NOTIFICATION_TYPES = [
def is_notification_email(
envelope: Dict[str, Any], content: Optional[str] = None
envelope: dict[str, Any], content: str | None = None
) -> bool:
"""Check if an email is a notification-style email.
@@ -127,8 +127,8 @@ def is_notification_email(
def classify_notification(
envelope: Dict[str, Any], content: Optional[str] = None
) -> Optional[NotificationType]:
envelope: dict[str, Any], content: str | None = None
) -> NotificationType | None:
"""Classify the type of notification email.
Args:
@@ -147,8 +147,8 @@ def classify_notification(
def extract_notification_summary(
content: str, notification_type: Optional[NotificationType] = None
) -> Dict[str, Any]:
content: str, notification_type: NotificationType | None = None
) -> dict[str, Any]:
"""Extract structured summary from notification email content.
Args:
@@ -185,7 +185,7 @@ def extract_notification_summary(
return summary
def _extract_gitlab_summary(content: str) -> Dict[str, Any]:
def _extract_gitlab_summary(content: str) -> dict[str, Any]:
"""Extract summary from GitLab notification."""
summary = {"action_items": [], "key_links": [], "metadata": {}}
@@ -219,7 +219,7 @@ def _extract_gitlab_summary(content: str) -> Dict[str, Any]:
return summary
def _extract_github_summary(content: str) -> Dict[str, Any]:
def _extract_github_summary(content: str) -> dict[str, Any]:
"""Extract summary from GitHub notification."""
summary = {"action_items": [], "key_links": [], "metadata": {}}
@@ -237,7 +237,7 @@ def _extract_github_summary(content: str) -> Dict[str, Any]:
return summary
def _extract_jira_summary(content: str) -> Dict[str, Any]:
def _extract_jira_summary(content: str) -> dict[str, Any]:
"""Extract summary from Jira notification."""
summary = {"action_items": [], "key_links": [], "metadata": {}}
@@ -263,7 +263,7 @@ def _extract_jira_summary(content: str) -> Dict[str, Any]:
return summary
def _extract_confluence_summary(content: str) -> Dict[str, Any]:
def _extract_confluence_summary(content: str) -> dict[str, Any]:
"""Extract summary from Confluence notification."""
summary = {"action_items": [], "key_links": [], "metadata": {}}
@@ -283,7 +283,7 @@ def _extract_confluence_summary(content: str) -> Dict[str, Any]:
return summary
def _extract_datadog_summary(content: str) -> Dict[str, Any]:
def _extract_datadog_summary(content: str) -> dict[str, Any]:
"""Extract summary from Datadog notification."""
summary = {"action_items": [], "key_links": [], "metadata": {}}
@@ -303,7 +303,7 @@ def _extract_datadog_summary(content: str) -> Dict[str, Any]:
return summary
def _extract_renovate_summary(content: str) -> Dict[str, Any]:
def _extract_renovate_summary(content: str) -> dict[str, Any]:
"""Extract summary from Renovate notification."""
summary = {"action_items": [], "key_links": [], "metadata": {}}
@@ -320,7 +320,7 @@ def _extract_renovate_summary(content: str) -> Dict[str, Any]:
return summary
def _extract_general_notification_summary(content: str) -> Dict[str, Any]:
def _extract_general_notification_summary(content: str) -> dict[str, Any]:
"""Extract summary from general notification."""
summary = {"action_items": [], "key_links": [], "metadata": {}}