Skip to content

Commit

Permalink
fix: add type ignores everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
amitkparekh committed Nov 29, 2023
1 parent 160edfc commit 3e69d02
Show file tree
Hide file tree
Showing 19 changed files with 437 additions and 35 deletions.
401 changes: 400 additions & 1 deletion poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ faiss-cpu = ">=1.7.3"
torch = ">=1.11.0,!=1.13.0,<2"
spacy = "3.7.2"
en-core-web-sm = { url = "https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.7.1/en_core_web_sm-3.7.1-py3-none-any.whl" }
transformers = ">=4.35.2"

[tool.poetry.group.dev.dependencies]
wemake-python-styleguide = ">=0.16.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def _create_synthetic_instruction(
"attributes": object_attributes.dict(),
}
else:
object_id = augmentation_instruction.object_id
object_id = augmentation_instruction.object_id # type: ignore[assignment]
object_attributes = augmentation_instruction.attributes

inventory_object_id = None
Expand Down Expand Up @@ -157,12 +157,12 @@ def __init__(self, object_synonyms: dict[str, list[str]]) -> None:
def __call__(self, augmentation_instruction: AugmentationInstruction) -> dict[str, Any]:
"""Create the search instruction dictionary."""
instruction_dict = super().__call__(augmentation_instruction=augmentation_instruction)
instruction_dict["positive"] = augmentation_instruction.augmentation_metadata["positive"]
instruction_dict["positive"] = augmentation_instruction.augmentation_metadata["positive"] # type: ignore[index]
return instruction_dict

def _create_mission_id(self, augmentation_instruction: AugmentationInstruction) -> str:
image_name = self._flat_image_name(augmentation_instruction.image_name)
positive = augmentation_instruction.augmentation_metadata["positive"]
positive = augmentation_instruction.augmentation_metadata["positive"] # type: ignore[index]
return f"{self.action_type}_ispositive{positive}_{augmentation_instruction.annotation_id}_{image_name}"


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def _merge_instructions(
action_instructions.extend(instructions)
else:
action_instructions.extend(object_instructions)
return action_instructions
return [dict(instruction) for instruction in action_instructions]

def _compute_distance_to_object(
self, object_annotation: dict[str, Any], robot_position: NDArray[np.float32]
Expand All @@ -223,7 +223,7 @@ def _get_instructions_from_attributes(
) -> tuple[list[AugmentationInstruction], int]:
instructions = []
bbox_centers = [
compute_bbox_center_coords(instruction.bbox) for instruction in instruction_list
compute_bbox_center_coords(instruction.bbox) for instruction in instruction_list # type: ignore[arg-type]
]

left2right = np.argsort([bbox_center[0] for bbox_center in bbox_centers])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def __call__(
attributes=SimBotObjectAttributes(
readable_name=readable_name,
color=self._get_color(readable_name),
distance=distance_to_object,
distance=distance_to_object, # type: ignore[arg-type]
),
bbox=self._get_bbox(image_annotation),
image_name=image_name,
Expand All @@ -93,7 +93,7 @@ def __call__(
break_instructions_dict[object_class].append(instruction)

break_instructions = self._merge_instructions(break_instructions_dict, annotation_id)
return break_instructions
return break_instructions # type: ignore[return-value]

@classmethod
def from_yaml_config( # type: ignore[override]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def __call__(
attributes=SimBotObjectAttributes(
readable_name=cleaning_readable_name,
color=self._get_color(readable_name),
distance=distance_to_object,
distance=distance_to_object, # type: ignore[arg-type]
),
bbox=self._get_bbox(image_annotation),
image_name=image_name,
Expand All @@ -101,7 +101,7 @@ def __call__(
clean_instructions_dict[object_class].append(instruction)

clean_instructions = self._merge_instructions(clean_instructions_dict, annotation_id)
return clean_instructions
return clean_instructions # type: ignore[return-value]

@classmethod
def from_yaml_config( # type: ignore[override]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def __call__( # noqa: WPS231
attributes=SimBotObjectAttributes(
readable_name=readable_name,
color=self._get_color(readable_name),
distance=distance_to_object,
distance=distance_to_object, # type: ignore[arg-type]
),
bbox=self._get_bbox(image_annotation),
image_name=image_name,
Expand All @@ -116,7 +116,7 @@ def __call__( # noqa: WPS231
clean_instructions_dict[object_class].append(instruction)

clean_instructions = self._merge_instructions(clean_instructions_dict, annotation_id)
return clean_instructions
return clean_instructions # type: ignore[return-value]

@classmethod
def from_yaml_config( # type: ignore[override]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def __call__(
attributes=SimBotObjectAttributes(
readable_name=readable_name,
color=self._get_color(readable_name),
distance=distance_to_object,
distance=distance_to_object, # type: ignore[arg-type]
),
bbox=self._get_bbox(image_annotation),
image_name=image_name,
Expand All @@ -89,7 +89,7 @@ def __call__(
navigation_instructions = self._merge_instructions(
navigation_instructions_dict, annotation_id
)
return navigation_instructions
return navigation_instructions # type: ignore[return-value]

@classmethod
def from_yaml_config( # type: ignore[override]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ def __call__(
object_id=object_type,
attributes=SimBotObjectAttributes(
readable_name=readable_name,
color=self._object_color_map.get(object_class, None),
distance=distance_to_object,
color=self._object_color_map.get(object_class, None), # type: ignore[arg-type]
distance=distance_to_object, # type: ignore[arg-type]
),
bbox=self._get_bbox(image_annotation),
image_name=image_name,
Expand All @@ -90,7 +90,7 @@ def __call__(
open_instructions_dict[object_class].append(instruction)

open_instructions = self._merge_instructions(open_instructions_dict, annotation_id)
return open_instructions
return open_instructions # type: ignore[return-value]

@classmethod
def from_yaml_config( # type: ignore[override]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def __call__(
attributes=SimBotObjectAttributes(
readable_name=readable_name,
color=self._get_color(readable_name),
distance=distance_to_object,
distance=distance_to_object, # type: ignore[arg-type]
),
bbox=self._get_bbox(image_annotation),
image_name=image_name,
Expand All @@ -88,7 +88,7 @@ def __call__(
pickup_instructions_dict[object_class].append(instruction)

pickup_instructions = self._merge_instructions(pickup_instructions_dict, annotation_id)
return pickup_instructions
return pickup_instructions # type: ignore[return-value]

@classmethod
def from_yaml_config( # type: ignore[override]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def __call__(
attributes=SimBotObjectAttributes(
readable_name=readable_name,
color=self._get_color(readable_name),
distance=distance_to_object,
distance=distance_to_object, # type: ignore[arg-type]
),
bbox=self._get_bbox(image_annotation),
image_name=image_name,
Expand All @@ -100,7 +100,7 @@ def __call__(
place_instructions_dict[object_class].append(instruction)

place_instructions = self._merge_instructions(place_instructions_dict, annotation_id)
return place_instructions
return place_instructions # type: ignore[return-value]

@classmethod
def from_yaml_config( # type: ignore[override]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def __call__(
attributes=SimBotObjectAttributes(
readable_name=readable_name,
color=self._get_color(readable_name),
distance=distance_to_object,
distance=distance_to_object, # type: ignore[arg-type]
),
bbox=self._get_bbox(image_annotation),
image_name=image_name,
Expand All @@ -88,7 +88,7 @@ def __call__(
scan_instructions_dict[object_class].append(instruction)

scan_instructions = self._merge_instructions(scan_instructions_dict, annotation_id)
return scan_instructions
return scan_instructions # type: ignore[return-value]

@classmethod
def from_yaml_config( # type: ignore[override]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def __call__( # noqa: WPS231
SimBotObjectAttributes(
readable_name=readable_name,
color=self._get_color(readable_name),
distance=distance_to_object,
distance=distance_to_object, # type: ignore[arg-type]
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def __call__(
attributes=SimBotObjectAttributes(
readable_name=readable_name,
color=self._get_color(readable_name),
distance=distance_to_object,
distance=distance_to_object, # type: ignore[arg-type]
),
bbox=self._get_bbox(image_annotation),
image_name=image_name,
Expand All @@ -88,7 +88,7 @@ def __call__(
toggle_instructions_dict[object_class].append(instruction)

toggle_instructions = self._merge_instructions(toggle_instructions_dict, annotation_id)
return toggle_instructions
return toggle_instructions # type: ignore[return-value]

@classmethod
def from_yaml_config( # type: ignore[override]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def gather(self) -> None:
for action_type, annotations_per_action_type in metadata_per_action_type.items():
final_metadata.update(
self.vision_data_augmentations[action_type].post_process_metadata(
annotations_per_action_type, self._class_thresholds
annotations_per_action_type, self._class_thresholds # type: ignore[arg-type]
)
)
progress.advance(task_id)
Expand Down Expand Up @@ -202,7 +202,7 @@ def __iter__(self) -> Iterator[dict[Any, Any]]:
annotations=annotations,
robot_position=robot_position,
image_name=image_name,
class_thresholds=self._class_thresholds,
class_thresholds=self._class_thresholds, # type: ignore[arg-type]
room_name=room_name,
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ def process_highl_level_key(self, session_id: str) -> HighLevelKey:
high_level_key = self._high_level_key_processor(session_id.split("/")[1])
except Exception:
logger.error(f"Could not convert the session id {session_id} to a high level key")
return None
return None # type: ignore[return-value]

return high_level_key

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def _filter_bboxes_based_on_area(
if thresholds is None:
threshold = self._default_min_area
else:
threshold = min(thresholds[0] * 5, self._default_min_area)
threshold = min(thresholds[0] * 5, self._default_min_area) # type: ignore[assignment]
for bbox in candidate_bboxes:
if compute_bbox_area(bbox) > threshold:
filtered_bboxes.append(bbox)
Expand Down Expand Up @@ -413,7 +413,7 @@ def __call__(
"""Filter the vision augmentation data."""
action = instruction_instance.actions[0]
if action.type == "Search":
search_object_metadata = action.search.get("selected_object", None)
search_object_metadata = action.search.get("selected_object", None) # type: ignore[attr-defined]
if search_object_metadata is None:
return False
target_object_id = search_object_metadata["id"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def __call__(self, highlevel_key: str) -> HighLevelKey:
if secondary_key == "YesterdayMachine_01" and decoded_key.target_object == "Carrot_01":
secondary_key = "YesterdayMachine_01_from_Carrot"

template_metadata = template_metadata[secondary_key]
template_metadata = template_metadata[secondary_key] # type: ignore[index]

for decoded_key_field in self.decoded_key_fields:
decoded_key_value = getattr(decoded_key, decoded_key_field)
Expand All @@ -247,11 +247,11 @@ def __call__(self, highlevel_key: str) -> HighLevelKey:
and decoded_key_value is not None
)
if should_get_object_synonym:
template_metadata[decoded_key_field] = get_object_synonym(decoded_key_value)
template_metadata[decoded_key_field] = get_object_synonym(decoded_key_value) # type: ignore[index]
else:
template_metadata[decoded_key_field] = decoded_key_value
template_metadata[decoded_key_field] = decoded_key_value # type: ignore[index]

formatted_paraphrases = self.get_paraphrases(template_metadata, decoded_key=decoded_key)
formatted_paraphrases = self.get_paraphrases(template_metadata, decoded_key=decoded_key) # type: ignore[arg-type]
return HighLevelKey(
decoded_key=decoded_key,
paraphrases=formatted_paraphrases,
Expand Down
2 changes: 2 additions & 0 deletions src/emma_datasets/datamodels/datasets/winoground.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ class WinogroundInstance(BaseInstance):
num_main_preds: int
collapsed_tag: str

@property
def modality(self) -> MediaType:
"""Returns the data modality for Winoground."""
return MediaType.image

@property
def features_path(self) -> Union[Path, list[Path]]:
"""Returns the features path for Winoground images."""
return Settings().paths.winoground_features.joinpath(f"{self.id}.pt")

0 comments on commit 3e69d02

Please sign in to comment.