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

[typing] TypeVar for broadcast rather than object #6731

Closed
kandluis opened this issue Mar 29, 2021 · 1 comment · Fixed by #6777
Closed

[typing] TypeVar for broadcast rather than object #6731

kandluis opened this issue Mar 29, 2021 · 1 comment · Fixed by #6777

Comments

@kandluis
Copy link
Contributor

The type for broadcast should probably be defined using TypeVar, rather than object since we only want to enforce that the input type is the same as the output type.

Something like:

T = TypeVar("T", bound=object)
def broadcast(self, obj: T, src: int = 0) -> T:
   ...

This would avoid requiring cast at the call-site when broadcasting elements.

https://github.com/PyTorchLightning/pytorch-lightning/blob/f79a13e4956554eb68b103c12054bdb7cd4dbe1a/pytorch_lightning/plugins/training_type/training_type_plugin.py#L90

@kandluis kandluis changed the title [typing] [typing] TypeVar for broadcast rather than object Mar 29, 2021
@tchaton
Copy link
Contributor

tchaton commented Mar 30, 2021

Dear @kandluis,

Great catch !
Would you mind making a PR to update the typing ?

Best,
T.C

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 a pull request may close this issue.

2 participants