Skip to content

Commit

Permalink
Refine type hint
Browse files Browse the repository at this point in the history
Refine type hint
  • Loading branch information
HAOCHENYE committed Oct 12, 2022
1 parent 762f92b commit e31d8c6
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions mmengine/model/base_model/data_preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
from mmengine.utils import is_list_of
from ..utils import stack_batch

CastData = Union[tuple, dict, BaseDataElement, torch.Tensor, list]
CastData = Union[tuple, dict, BaseDataElement, torch.Tensor, list, bytes, str,
None]


@MODELS.register_module()
Expand Down Expand Up @@ -43,7 +44,7 @@ def cast_data(self, data: CastData) -> CastData:
if isinstance(data, Mapping):
return {key: self.cast_data(data[key]) for key in data}
elif isinstance(data, (str, bytes)) or data is None:
return data # type: ignore
return data
elif isinstance(data, tuple) and hasattr(data, '_fields'):
# namedtuple
return type(data)(*(self.cast_data(sample)for sample in data)) # type: ignore # noqa: E501 # yapf:disable
Expand Down

0 comments on commit e31d8c6

Please sign in to comment.