Skip to content

Commit

Permalink
fix: fix mypy and flake8 issues
Browse files Browse the repository at this point in the history
after mypy and flake8 upgrade
  • Loading branch information
raphael0202 committed Nov 25, 2022
1 parent a44a349 commit 80fef79
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 23 deletions.
9 changes: 3 additions & 6 deletions robotoff/app/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1075,12 +1075,9 @@ def on_get(self, req: falcon.Request, resp: falcon.Response):

class DumpResource:
def on_get(self, req: falcon.Request, resp: falcon.Response):
keep_types: Optional[List[str]] = req.get_param_as_list(
"insight_types", required=False
)

if keep_types is not None:
keep_types = keep_types[:10]
keep_types: List[str] = req.get_param_as_list(
"insight_types", required=False, default=[]
)[:10]

barcode = req.get_param("barcode")
annotated = req.get_param_as_bool("annotated", blank_as_true=False)
Expand Down
10 changes: 5 additions & 5 deletions robotoff/app/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ def _add_vote_exclusions(

def get_insights(
barcode: Optional[str] = None,
keep_types: List[str] = None,
country: str = None,
brands: List[str] = None,
keep_types: Optional[List[str]] = None,
country: Optional[str] = None,
brands: Optional[List[str]] = None,
annotated: Optional[bool] = False,
annotation: Optional[int] = None,
order_by: Optional[str] = None,
Expand Down Expand Up @@ -199,7 +199,7 @@ def get_images(

def get_predictions(
barcode: Optional[str] = None,
keep_types: List[str] = None,
keep_types: Optional[List[str]] = None,
value_tag: Optional[str] = None,
server_domain: Optional[str] = None,
limit: Optional[int] = 25,
Expand Down Expand Up @@ -393,7 +393,7 @@ def save_annotation(

def get_logo_annotation(
barcode: Optional[str] = None,
keep_types: List[str] = None,
keep_types: Optional[List[str]] = None,
value_tag: Optional[str] = None,
server_domain: Optional[str] = None,
limit: Optional[int] = 25,
Expand Down
3 changes: 2 additions & 1 deletion robotoff/app/events.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from multiprocessing import Process, SimpleQueue
from typing import Optional

import requests

Expand Down Expand Up @@ -48,7 +49,7 @@ def send_event(
event_type: str,
user_id: str,
device_id: str,
barcode: str = None,
barcode: Optional[str] = None,
):
event = {
"event_type": event_type,
Expand Down
6 changes: 4 additions & 2 deletions robotoff/insights/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,9 @@ def update_fields(
setattr(reference_insight, field_name, getattr(insight, field_name))

@classmethod
def add_optional_fields(cls, insight: ProductInsight, product: Product):
def add_optional_fields( # noqa: B027
cls, insight: ProductInsight, product: Product
):
"""Overwrite this method in children classes to add optional fields.
The `campaign` field should be populated here.
Expand Down Expand Up @@ -1033,7 +1035,7 @@ def import_product_predictions(
return batch_insert(PredictionModel, to_import, 50)


IMPORTERS: List[Type[InsightImporter]] = [
IMPORTERS: List[Type] = [
PackagerCodeInsightImporter,
LabelInsightImporter,
CategoryImporter,
Expand Down
4 changes: 2 additions & 2 deletions robotoff/off.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def is_valid_image(barcode: str, image_id: str) -> bool:

def get_product(
barcode: str,
fields: List[str] = None,
fields: Optional[List[str]] = None,
server: Optional[Union[ServerType, str]] = None,
timeout: Optional[int] = 10,
) -> Optional[Dict]:
Expand Down Expand Up @@ -358,7 +358,7 @@ def save_ingredients(
barcode: str,
ingredient_text: str,
insight_id: Optional[str] = None,
lang: str = None,
lang: Optional[str] = None,
comment: Optional[str] = None,
**kwargs,
):
Expand Down
4 changes: 2 additions & 2 deletions robotoff/prediction/object_detection/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def detect_from_image(
dtype=np.float32,
)
.reshape((1, 1))
.astype(np.int)[0][0]
.astype(np.int)[0][0] # type: ignore
)
detection_scores = np.frombuffer(
response.raw_output_contents[output_index["detection_scores"]],
Expand All @@ -166,7 +166,7 @@ def detect_from_image(
dtype=np.float32,
)
.reshape((1, -1))
.astype(np.int)
.astype(np.int) # type: ignore
)[0]
detection_boxes = np.frombuffer(
response.raw_output_contents[output_index["detection_boxes"]],
Expand Down
2 changes: 1 addition & 1 deletion robotoff/prediction/ocr/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def is_barcode(text: str):


def get_source(
image_name: str, json_path: str = None, barcode: Optional[str] = None
image_name: str, json_path: Optional[str] = None, barcode: Optional[str] = None
) -> str:
if not barcode:
barcode = get_barcode_from_path(str(json_path))
Expand Down
3 changes: 1 addition & 2 deletions robotoff/utils/cache.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import abc
import datetime
from typing import Callable, Optional

Expand All @@ -7,7 +6,7 @@
logger = get_logger(__name__)


class CachedStore(metaclass=abc.ABCMeta):
class CachedStore:
def __init__(self, fetch_func: Callable, expiration_interval: Optional[int] = 30):
self.store = None
self.expires_after: Optional[datetime.datetime] = None
Expand Down
4 changes: 2 additions & 2 deletions robotoff/workers/client.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from multiprocessing.connection import Client
from typing import Dict
from typing import Dict, Optional

from robotoff import settings
from robotoff.utils import get_logger

logger = get_logger(__name__)


def send_ipc_event(event_type: str, meta: Dict = None):
def send_ipc_event(event_type: str, meta: Optional[Dict] = None):
meta = meta or {}

logger.info("Connecting listener server on {}:{}" "".format(*settings.IPC_ADDRESS))
Expand Down

0 comments on commit 80fef79

Please sign in to comment.