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