fix: resolve CI type annotation issues
Some checks failed
CI / test (push) Has been cancelled
CI / build (push) Has been cancelled

- Replaced deprecated typing.List/Dict/Tuple with native list/dict/tuple
- Fixed trailing whitespace issues
- Fixed blank line whitespace issues
- Removed unused variables and imports
- Applied black formatting
This commit is contained in:
2026-02-02 12:45:11 +00:00
parent d8434c1553
commit dc02c0fdae

View File

@@ -1,8 +1,8 @@
"""NLP analyzer for extracting structured information from requirements.""" """NLP analyzer for extracting structured information from requirements."""
from dataclasses import dataclass, field from dataclasses import dataclass, field
from enum import Enum from enum import Enum
from typing import Any, Dict, List, Optional, TYPE_CHECKING from typing import TYPE_CHECKING, Any, Optional
import spacy import spacy
from spacy.tokens import Doc from spacy.tokens import Doc
@@ -13,6 +13,7 @@ if TYPE_CHECKING:
class ActorType(str, Enum): class ActorType(str, Enum):
"""Types of actors in requirements.""" """Types of actors in requirements."""
USER = "user" USER = "user"
SYSTEM = "system" SYSTEM = "system"
ADMIN = "admin" ADMIN = "admin"
@@ -22,6 +23,7 @@ class ActorType(str, Enum):
class ActionType(str, Enum): class ActionType(str, Enum):
"""Types of actions in requirements.""" """Types of actions in requirements."""
CREATE = "create" CREATE = "create"
READ = "read" READ = "read"
UPDATE = "update" UPDATE = "update"
@@ -41,6 +43,7 @@ class ActionType(str, Enum):
@dataclass @dataclass
class RequirementAnalysis: class RequirementAnalysis:
"""Structured analysis of a requirement.""" """Structured analysis of a requirement."""
raw_text: str raw_text: str
actor: Optional[str] = None actor: Optional[str] = None
actor_type: ActorType = ActorType.UNKNOWN actor_type: ActorType = ActorType.UNKNOWN
@@ -49,10 +52,10 @@ class RequirementAnalysis:
target: Optional[str] = None target: Optional[str] = None
condition: Optional[str] = None condition: Optional[str] = None
benefit: Optional[str] = None benefit: Optional[str] = None
examples: List[str] = field(default_factory=list) examples: list[str] = field(default_factory=list)
variables: Dict[str, str] = field(default_factory=dict) variables: dict[str, str] = field(default_factory=dict)
def to_dict(self) -> Dict[str, Any]: def to_dict(self) -> dict[str, Any]:
"""Convert to dictionary.""" """Convert to dictionary."""
return { return {
"raw_text": self.raw_text, "raw_text": self.raw_text,
@@ -73,7 +76,7 @@ class NLPAnalyzer:
def __init__(self, model: str = "en_core_web_sm"): def __init__(self, model: str = "en_core_web_sm"):
"""Initialize the analyzer with a spaCy model. """Initialize the analyzer with a spaCy model.
Args: Args:
model: spaCy model name. Defaults to en_core_web_sm. model: spaCy model name. Defaults to en_core_web_sm.
""" """
@@ -81,6 +84,7 @@ class NLPAnalyzer:
self.nlp = spacy.load(model) self.nlp = spacy.load(model)
except OSError: except OSError:
import subprocess import subprocess
subprocess.run( subprocess.run(
["python", "-m", "spacy", "download", model], ["python", "-m", "spacy", "download", model],
check=True, check=True,
@@ -89,10 +93,10 @@ class NLPAnalyzer:
def analyze(self, text: str) -> RequirementAnalysis: def analyze(self, text: str) -> RequirementAnalysis:
"""Analyze a requirement text and extract structured information. """Analyze a requirement text and extract structured information.
Args: Args:
text: The natural language requirement text. text: The natural language requirement text.
Returns: Returns:
RequirementAnalysis with extracted components. RequirementAnalysis with extracted components.
""" """
@@ -224,10 +228,10 @@ class NLPAnalyzer:
def analyze_ambiguity(self, text: str) -> "list[AmbiguityWarning]": def analyze_ambiguity(self, text: str) -> "list[AmbiguityWarning]":
"""Analyze text for ambiguous language. """Analyze text for ambiguous language.
Args: Args:
text: The text to analyze. text: The text to analyze.
Returns: Returns:
List of ambiguity warnings. List of ambiguity warnings.
""" """