From d8434c15530daf9a4b240c4dab145c43c6d738c3 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Mon, 2 Feb 2026 12:45:10 +0000 Subject: [PATCH] fix: resolve CI type annotation issues - 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 --- src/nl2gherkin/nlp/ambiguity.py | 115 ++++++++++++++++++++++---------- 1 file changed, 80 insertions(+), 35 deletions(-) diff --git a/src/nl2gherkin/nlp/ambiguity.py b/src/nl2gherkin/nlp/ambiguity.py index 22d96e3..af31cd9 100644 --- a/src/nl2gherkin/nlp/ambiguity.py +++ b/src/nl2gherkin/nlp/ambiguity.py @@ -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,35 +44,79 @@ 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: text: The requirement text to analyze. - + 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