fix: resolve CI/CD linting and formatting issues
Some checks failed
CI / test (3.10) (push) Has been cancelled
CI / test (3.11) (push) Has been cancelled
CI / test (3.12) (push) Has been cancelled
CI / test (3.9) (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / build (push) Has been cancelled

- Replaced deprecated typing.Dict/List/Tuple with native types (UP035)
- Removed unused imports across all modules
- Fixed unused variables by replacing with _ prefix
- Added missing Optional type imports
- Reorganized imports for proper sorting (I001)
- Applied black formatting to all source files
This commit is contained in:
2026-02-02 08:52:02 +00:00
parent 15b3e04647
commit cdde9f629d

View File

@@ -1,14 +1,15 @@
"""Base parser class and data structures."""
'''Base parser class and data structures.'''
from abc import ABC, abstractmethod
from dataclasses import dataclass, field
from datetime import datetime
from typing import Any, Dict, List, Optional
from enum import Enum
from typing import Any, Optional
class LogFormat(Enum):
"""Supported log formats."""
'''Supported log formats.'''
JSON = "json"
SYSLOG = "syslog"
APACHE = "apache"
@@ -17,7 +18,8 @@ class LogFormat(Enum):
@dataclass
class ParsedLogEntry:
"""Represents a parsed log entry."""
'''Represents a parsed log entry.'''
raw_line: str
timestamp: Optional[datetime] = None
level: Optional[str] = None
@@ -27,12 +29,12 @@ class ParsedLogEntry:
facility: Optional[str] = None
severity: Optional[str] = None
logger: Optional[str] = None
extra: Dict[str, Any] = field(default_factory=dict)
extra: dict[str, Any] = field(default_factory=dict)
line_number: int = 0
error_pattern: Optional[str] = None
def to_dict(self) -> Dict[str, Any]:
"""Convert to dictionary."""
def to_dict(self) -> dict[str, Any]:
'''Convert to dictionary.'''
result = {
"raw_line": self.raw_line,
"message": self.message,
@@ -60,22 +62,22 @@ class ParsedLogEntry:
class LogParser(ABC):
"""Abstract base class for log parsers."""
'''Abstract base class for log parsers.'''
format_name: str = "base"
@abstractmethod
def parse(self, line: str, line_number: int = 0) -> Optional[ParsedLogEntry]:
"""Parse a single log line."""
'''Parse a single log line.'''
pass
@abstractmethod
def can_parse(self, line: str) -> bool:
"""Check if this parser can handle the given line."""
'''Check if this parser can handle the given line.'''
pass
def parse_batch(self, lines: List[str]) -> List[ParsedLogEntry]:
"""Parse multiple lines."""
def parse_batch(self, lines: list[str]) -> list[ParsedLogEntry]:
'''Parse multiple lines.'''
results = []
for i, line in enumerate(lines, 1):
try:
@@ -83,9 +85,5 @@ class LogParser(ABC):
if entry:
results.append(entry)
except Exception:
results.append(ParsedLogEntry(
raw_line=line,
message="Parse error",
line_number=i
))
results.append(ParsedLogEntry(raw_line=line, message="Parse error", line_number=i))
return results