Fix bare except handlers in keyword_extractor.py #20

Merged
llabeyrie merged 1 commits from fix/narrow-except-handlers into main 2026-03-19 18:39:36 +00:00
Showing only changes of commit 3cfb18be11 - Show all commits

View File

@@ -2,8 +2,11 @@
from __future__ import annotations
import logging
import math
import re
logger = logging.getLogger(__name__)
from dataclasses import dataclass, field
from typing import Any, Dict, Iterable, List, Mapping, Optional, Sequence, Set, Tuple
@@ -199,7 +202,8 @@ class KeywordExtractor:
def _extract_yake_scores(self, text: str) -> Dict[str, float]:
try:
import yake
except Exception:
except ImportError:
logger.warning("yake not installed, skipping relevance scoring")
return {}
text_token_count = len(text.split())
@@ -208,7 +212,8 @@ class KeywordExtractor:
try:
extractor = yake.KeywordExtractor(lan="en", n=2, dedupLim=0.9, top=top_n)
phrase_scores = extractor.extract_keywords(text)
except Exception:
except (ValueError, TypeError) as e:
logger.warning("YAKE extraction failed: %s", e)
return {}
token_scores: Dict[str, float] = {}