fix: resolve CI type annotation issues
Some checks failed
CI / build (push) Has been cancelled
CI / test (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:10 +00:00
parent 2aca3fca65
commit d8434c1553

View File

@@ -2,11 +2,12 @@
from dataclasses import dataclass
from enum import Enum
from typing import Any, Dict, List, Optional
from typing import Any, Optional
class AmbiguityType(str, Enum):
"""Types of ambiguity in requirements."""
PRONOUN = "pronoun"
VAGUE_QUANTIFIER = "vague_quantifier"
TEMPORAL = "temporal"
@@ -19,6 +20,7 @@ class AmbiguityType(str, Enum):
@dataclass
class AmbiguityWarning:
"""A warning about ambiguous language in a requirement."""
type: AmbiguityType
message: str
position: int = 0
@@ -26,7 +28,7 @@ class AmbiguityWarning:
suggestion: Optional[str] = None
severity: str = "medium"
def to_dict(self) -> Dict[str, Any]:
def to_dict(self) -> dict[str, Any]:
"""Convert to dictionary."""
return {
"type": self.type.value,
@@ -42,26 +44,70 @@ class AmbiguityDetector:
"""Detector for ambiguous language in requirements."""
PRONOUNS = {
"it", "they", "them", "he", "she", "this", "that", "these", "those",
"its", "their", "his", "her", "which", "what", "who", "whom",
"it",
"they",
"them",
"he",
"she",
"this",
"that",
"these",
"those",
"its",
"their",
"his",
"her",
"which",
"what",
"who",
"whom",
}
VAGUE_QUANTIFIERS = {
"some", "many", "few", "several", "various", "multiple", "somewhat",
"roughly", "approximately", "generally", "usually", "often", "sometimes",
"occasionally", "maybe", "possibly", "probably", "likely",
"some",
"many",
"few",
"several",
"various",
"multiple",
"somewhat",
"roughly",
"approximately",
"generally",
"usually",
"often",
"sometimes",
"occasionally",
"maybe",
"possibly",
"probably",
"likely",
}
TEMPORAL_AMBIGUITIES = {
"soon", "later", "eventually", "eventually", "currently", "presently",
"before long", "in the future", "at some point", "eventually",
"soon",
"later",
"eventually",
"eventually",
"currently",
"presently",
"before long",
"in the future",
"at some point",
"eventually",
}
CONDITIONAL_KEYWORDS = {
"if", "when", "unless", "provided", "given", "assuming", "while",
"if",
"when",
"unless",
"provided",
"given",
"assuming",
"while",
}
def detect(self, text: str) -> List[AmbiguityWarning]:
def detect(self, text: str) -> list[AmbiguityWarning]:
"""Detect ambiguities in the given text.
Args:
@@ -70,7 +116,7 @@ class AmbiguityDetector:
Returns:
List of ambiguity warnings.
"""
warnings: List[AmbiguityWarning] = []
warnings: list[AmbiguityWarning] = []
warnings.extend(self._detect_pronouns(text))
warnings.extend(self._detect_vague_quantifiers(text))
@@ -80,9 +126,9 @@ class AmbiguityDetector:
return warnings
def _detect_pronouns(self, text: str) -> List[AmbiguityWarning]:
def _detect_pronouns(self, text: str) -> list[AmbiguityWarning]:
"""Detect pronoun usage that may be ambiguous."""
warnings: List[AmbiguityWarning] = []
warnings: list[AmbiguityWarning] = []
words = text.split()
@@ -103,9 +149,9 @@ class AmbiguityDetector:
return warnings
def _detect_vague_quantifiers(self, text: str) -> List[AmbiguityWarning]:
def _detect_vague_quantifiers(self, text: str) -> list[AmbiguityWarning]:
"""Detect vague quantifiers that lack precision."""
warnings: List[AmbiguityWarning] = []
warnings: list[AmbiguityWarning] = []
words = text.split()
@@ -136,9 +182,9 @@ class AmbiguityDetector:
return warnings
def _detect_temporal_ambiguities(self, text: str) -> List[AmbiguityWarning]:
def _detect_temporal_ambiguities(self, text: str) -> list[AmbiguityWarning]:
"""Detect temporal ambiguities in the text."""
warnings: List[AmbiguityWarning] = []
warnings: list[AmbiguityWarning] = []
words = text.split()
@@ -159,32 +205,31 @@ class AmbiguityDetector:
return warnings
def _detect_missing_conditions(self, text: str) -> List[AmbiguityWarning]:
def _detect_missing_conditions(self, text: str) -> list[AmbiguityWarning]:
"""Detect potential missing conditions in requirements."""
warnings: List[AmbiguityWarning] = []
warnings: list[AmbiguityWarning] = []
import re
has_conditional = any(
re.search(r"\b" + kw + r"\b", text, re.IGNORECASE)
for kw in self.CONDITIONAL_KEYWORDS
re.search(r"\b" + kw + r"\b", text, re.IGNORECASE) for kw in self.CONDITIONAL_KEYWORDS
)
action_patterns = [
r"\bmust\b", r"\bshall\b", r"\bshould\b", r"\bwill\b",
r"\bcan\b", r"\benable\b", r"\ballow\b",
r"\bmust\b",
r"\bshall\b",
r"\bshould\b",
r"\bwill\b",
r"\bcan\b",
r"\benable\b",
r"\ballow\b",
]
has_action = any(
re.search(pattern, text, re.IGNORECASE)
for pattern in action_patterns
)
has_action = any(re.search(pattern, text, re.IGNORECASE) for pattern in action_patterns)
if has_action and not has_conditional:
action_match = re.search(
r"(must|shall|should|will|can|enable|allow)\s+\w+",
text,
re.IGNORECASE
r"(must|shall|should|will|can|enable|allow)\s+\w+", text, re.IGNORECASE
)
if action_match:
warnings.append(
@@ -200,9 +245,9 @@ class AmbiguityDetector:
return warnings
def _detect_passive_voice(self, text: str) -> List[AmbiguityWarning]:
def _detect_passive_voice(self, text: str) -> list[AmbiguityWarning]:
"""Detect passive voice usage."""
warnings: List[AmbiguityWarning] = []
warnings: list[AmbiguityWarning] = []
import re