Fix some typing problems (#1940)

* Fix some typing problems

* nerfstudio.data typing error fixes

* Add tiny fixes

* Remove ABC from pipeline

* Prevent circular imports

* Tweak ModuleList typing

* TrainingCallbackAttributes cleanup

* Various minor nits

* More nits

* Run `ruff`

---------

Co-authored-by: Brent Yi <yibrenth@gmail.com>
This commit is contained in:
Jonáš KulhánekandBrent Yi authored and GitHub committed 2023-05-17 17:36:56 -07:00
1 parent c6111e377e
commit f481f5ebec
27 files changed
+154 -75

No files matched your search

+7 -4
View File
@@ -17,12 +17,15 @@ Miscellaneous helper code.
"""
from typing import Any, Callable, Dict, List, Optional, Union
from typing import Any, Callable, Dict, List, Optional, TypeVar, Union
import torch
T = TypeVar("T")
TKey = TypeVar("TKey")
def get_dict_to_torch(stuff: Any, device: Union[torch.device, str] = "cpu", exclude: Optional[List[str]] = None):
def get_dict_to_torch(stuff: T, device: Union[torch.device, str] = "cpu", exclude: Optional[List[str]] = None) -> T:
"""Set everything in the dict to the specified torch device.
Args:
@@ -42,7 +45,7 @@ def get_dict_to_torch(stuff: Any, device: Union[torch.device, str] = "cpu", excl
return stuff
def get_dict_to_cpu(stuff: Any):
def get_dict_to_cpu(stuff: T) -> T:
"""Set everything in the dict to CPU.
Args:
@@ -57,7 +60,7 @@ def get_dict_to_cpu(stuff: Any):
return stuff
def get_masked_dict(d, mask):
def get_masked_dict(d: Dict[TKey, torch.Tensor], mask) -> Dict[TKey, torch.Tensor]:
"""Return a masked dictionary.
TODO(ethan): add more asserts/checks so this doesn't have unpredictable behavior.
+1 -1
View File
@@ -148,7 +148,7 @@ def vis_dataset(
),
)
fig = go.Figure(data=data, layout=layout) # type: ignore
return fig
return fig # type: ignore
def get_random_color(colormap: Optional[List[str]] = None, idx: Optional[int] = None) -> str:
+1 -2
View File
@@ -127,9 +127,8 @@ class TensorDataclass:
new_dict = {}
for k, v in dict_.items():
if isinstance(v, torch.Tensor):
# If custom dimension key, then we need to
# Apply field-specific custom dimensions.
if isinstance(self._field_custom_dimensions, dict) and k in self._field_custom_dimensions:
# pylint: disable=unsubscriptable-object
new_dict[k] = v.broadcast_to(
(
*batch_shape,