Skip to content

Commit

Permalink
fix: fix mypy typing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
raphael0202 committed Apr 27, 2023
1 parent 15eb2f8 commit 107cc23
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions robotoff/prediction/ocr/packager_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ def generate_USDA_code_keyword_processor() -> KeywordProcessor:
def extract_USDA_code(processor: KeywordProcessor, text: str) -> Optional[str]:
"""Given a string, returns the USDA code it contains or None"""
USDA_code = None

for (USDA_code_keyword, _) in processor.extract_keywords(text):
matches: list[tuple[str, str]] = processor.extract_keywords(text) # type: ignore
for (USDA_code_keyword, _) in matches:
USDA_code = USDA_code_keyword
# Once we found a match we can return the code
# as there should not be more than one match
Expand Down
16 changes: 8 additions & 8 deletions robotoff/utils/text/flashtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import os
import string
from pathlib import Path
from typing import Optional, Union
from typing import Any, Optional, Union


class KeywordProcessor:
Expand Down Expand Up @@ -128,23 +128,23 @@ def __getitem__(self, word: str) -> Optional[str]:

return None

def __setitem__(self, keyword: str, clean_name: Optional[str] = None) -> bool:
def __setitem__(self, keyword: str, clean_name: Optional[Any] = None) -> bool:
"""To add keyword to the dictionary
pass the keyword and the clean name it maps to.
Args:
keyword : string
keyword that you want to identify
clean_name : string
clean_name : Any
clean term for that keyword that you would want to get back in return or replace
if not provided, keyword will be used as the clean name also.
Examples:
>>> keyword_processor['Big Apple'] = 'New York'
"""
status = False
if not clean_name and keyword:
if clean_name is None and keyword:
clean_name = keyword

if keyword and clean_name:
Expand Down Expand Up @@ -228,15 +228,15 @@ def add_non_word_boundary(self, character: str) -> None:
"""
self.non_word_boundaries.add(character)

def add_keyword(self, keyword: str, clean_name: Optional[str] = None) -> bool:
def add_keyword(self, keyword: str, clean_name: Optional[Any] = None) -> bool:
"""To add one or more keywords to the dictionary
pass the keyword and the clean name it maps to.
Args:
keyword : string
keyword that you want to identify
clean_name : string
clean_name : Any
clean term for that keyword that you would want to get back in return or replace
if not provided, keyword will be used as the clean name also.
Expand Down Expand Up @@ -463,7 +463,7 @@ def get_all_keywords(

def extract_keywords(
self, sentence: str, span_info: bool = False, max_cost: int = 0
) -> list[Union[str, tuple[str, int, int]]]:
) -> list[Union[Any, tuple[Any, int, int]]]:
"""Searches in the string for all keywords present in corpus.
Keywords present are added to a list `keywords_extracted` and returned.
Expand All @@ -487,7 +487,7 @@ def extract_keywords(
>>> keywords_found
>>> ['New York', 'Bay Area']
"""
keywords_extracted: list[Union[str, tuple[str, int, int]]] = []
keywords_extracted: list[Union[Any, tuple[Any, int, int]]] = []
if not sentence:
# if sentence is empty or none just return empty list
return keywords_extracted
Expand Down

0 comments on commit 107cc23

Please sign in to comment.