-
-
Notifications
You must be signed in to change notification settings - Fork 986
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
Add param_store.py
type hints
#3271
Conversation
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.
This is great! just one nit
constrained_value = transform_to(constraint)(unconstrained_value) | ||
constrained_value.unconstrained = weakref.ref(unconstrained_value) | ||
constrained_value: torch.Tensor = transform_to(constraint)(unconstrained_value) | ||
constrained_value.unconstrained = weakref.ref(unconstrained_value) # type: ignore[attr-defined] |
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.
neat, I haven't seen the error-specific type: ignore[-]
syntax before. Did you add it manually, or via an IDE that automatically finds the narrowest ignore?
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.
It's an output from mypy error message:
pyro/params/param_store.py:134: error: "Tensor" has no attribute "unconstrained" [attr-defined]
But github copilot is also pretty good at finding those.
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.
Also described here: https://mypy.readthedocs.io/en/stable/common_issues.html#spurious-errors-and-locally-silencing-the-checker
You can use the form # type: ignore[<code>] to only ignore specific errors on the line. This way you are less likely to silence unexpected errors that are not safe to ignore, and this will also document what the purpose of the comment is. See Error codes for more information.
Replaces #3148