Skip to content

chore: add type hints to utility functions in functionals.py#388

Open
guozhihao-224 wants to merge 1 commit intoalibaba:mainfrom
guozhihao-224:chore/add-type-hints-functionals-part1
Open

chore: add type hints to utility functions in functionals.py#388
guozhihao-224 wants to merge 1 commit intoalibaba:mainfrom
guozhihao-224:chore/add-type-hints-functionals-part1

Conversation

@guozhihao-224
Copy link

Summary

Adds complete type annotations to 6 simple utility functions in roll/utils/functionals.py.

Functions Updated

  • tensor_to_cpu_visitor(obj: Any, path: tuple) -> bool
  • tensor_to_cuda_visitor(obj: Any, path: tuple) -> bool
  • delete_tensor_grad_visitor(obj: Any, path: tuple) -> bool
  • traverse_obj(value: Any, visitor: Callable[[Any, tuple], bool], path: tuple = ()) -> None
  • flatten_sum(values: list | tuple) -> float
  • masked_var(values: torch.Tensor, mask: torch.Tensor, unbiased: bool = True) -> torch.Tensor

Other Changes

  • Translated Chinese docstrings to English
  • Added Google-style docstrings (Args, Returns, Raises)
  • Added Any, Callable to typing imports

Testing

  • ✅ Syntax check passed

Related Issue

Part of #387

@CLAassistant
Copy link

CLAassistant commented Mar 18, 2026

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants