-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Fix mypy for utilities.xla_device
#8755
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
Fix mypy for utilities.xla_device
#8755
Conversation
Codecov Report
@@ Coverage Diff @@
## master #8755 +/- ##
======================================
Coverage 89% 89%
======================================
Files 169 169
Lines 14073 14074 +1
======================================
+ Hits 12466 12467 +1
Misses 1607 1607 |
| _TORCHMETRICS_LOWER_THAN_0_3 = _compare_version("torchmetrics", operator.lt, "0.3.0") | ||
| _TORCHMETRICS_GREATER_EQUAL_0_3 = _compare_version("torchmetrics", operator.ge, "0.3.0") | ||
| _XLA_AVAILABLE = _module_available("torch_xla") | ||
| _XLA_AVAILABLE: bool = _module_available("torch_xla") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this necessary?
_module_available is annotated with -> bool
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, mypy is not able to figure that out without this explicit type hint.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can confirm, we had the same problem in metrics:
https://github.com/PyTorchLightning/metrics/blob/525642df8c3f3f5f93cdd22b6b9cd802a3854634/torchmetrics/utilities/imports.py#L79-L80
* Fix mypy for utilities.xla_device * Add explicit type hint for _XLA_AVAILABLE in utilities.imports
What does this PR do?
Part of #7037. This PR disentangles large #7218. It fixes mypy typing in
utilities.xla_device.py.Does your PR introduce any breaking changes? If yes, please list them.
None
Before submitting
PR review
Anyone in the community is welcome to review the PR.
Before you start reviewing make sure you have read Review guidelines. In short, see the following bullet-list:
Did you have fun?
Make sure you had fun coding 🙃