-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Incorrect type hints for LightningModule.load_from_checkpoint #15730
Comments
I'm able to reproduce this outside of PL, so I opened an issue with typing-extensions: python/typing_extensions#96 |
Feedback from python/typing_extensions#96 is that the latest release of mypy does not yet know how to handle |
@adamjstewart This was recently added in #15496. See the explanation here: #15496 (comment) cc @carmocca |
Exactly. You can install the latest mypy by following the instructions at https://github.com/python/mypy#quick-start. I expect they'll make a release within the next month. |
Decided to manually cast things to the right type for now. Will look out for the new mypy release. Thanks for the pointers! |
Bug description
The
LightningModule.load_from_checkpoint
function appears to return typeSelf?
instead ofLightningModule
.How to reproduce the bug
First, create a
test.py
file containing the following code:Then, run mypy on this file:
You'll notice that the type of the second model is incorrect, so mypy raises an error when you try to access LightningModule attributes like
hparams
.Error messages and logs
We hit this issue in CI after the release of 1.8.1, so this may have been introduced in 1.8.1.
https://github.com/microsoft/torchgeo/actions/runs/3499809303/jobs/5861774881
Environment
More info
I'm happy to submit a PR to fix this issue if someone wants to point me in the right direction. I have dozens of other typing issues with PL, so would love to be able to fix those as well.
cc @Borda
The text was updated successfully, but these errors were encountered: