Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(bugfix): Fix mypy typing error + precommit issue #865

Merged
merged 2 commits into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/tutorials/nb_python/Habitat2_Quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# extension: .py
# format_name: percent
# format_version: '1.3'
# jupytext_version: 1.13.6
# jupytext_version: 1.13.8
# kernelspec:
# display_name: Python 3
# name: python3
Expand Down
2 changes: 1 addition & 1 deletion examples/tutorials/nb_python/habitat2_gym_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# extension: .py
# format_name: percent
# format_version: '1.3'
# jupytext_version: 1.13.6
# jupytext_version: 1.13.8
# kernelspec:
# display_name: Python 3
# name: python3
Expand Down
19 changes: 17 additions & 2 deletions habitat/core/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@
import abc
from collections import OrderedDict
from enum import Enum
from typing import Any, Dict, Iterable, List, Optional, Sequence, Union
from typing import (
TYPE_CHECKING,
Any,
Dict,
Iterable,
List,
Optional,
Sequence,
Union,
)

import attr
import numpy as np
Expand All @@ -16,7 +25,13 @@
from habitat.config import Config
from habitat.core.dataset import Episode

VisualObservation = Union[np.ndarray]
if TYPE_CHECKING:
try:
from torch import Tensor
except ImportError:
pass

VisualObservation = Union[np.ndarray, "Tensor"]


@attr.s(auto_attribs=True)
Expand Down
4 changes: 3 additions & 1 deletion habitat/sims/habitat_simulator/habitat_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ class HabitatSimFisheyeSemanticSensor(HabitatSimSemanticSensor):
_get_default_spec = habitat_sim.FisheyeSensorDoubleSphereSpec


def check_sim_obs(obs: Optional[np.ndarray], sensor: Sensor) -> None:
def check_sim_obs(
obs: Union[np.ndarray, "Tensor", None], sensor: Sensor
) -> None:
assert obs is not None, (
"Observation corresponding to {} not present in "
"simulator's observations".format(sensor.uuid)
Expand Down