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

Add param_store.py type hints #3271

Merged
merged 9 commits into from
Oct 4, 2023
Merged

Add param_store.py type hints #3271

merged 9 commits into from
Oct 4, 2023

Conversation

ordabayevy
Copy link
Member

Replaces #3148

tests/conftest.py Outdated Show resolved Hide resolved
Copy link
Member

@fritzo fritzo left a 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]
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member Author

@ordabayevy ordabayevy Oct 4, 2023

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.

pyro/params/param_store.py Outdated Show resolved Hide resolved
@ordabayevy ordabayevy requested a review from fritzo October 4, 2023 21:25
@ordabayevy ordabayevy merged commit c00bcc3 into dev Oct 4, 2023
9 checks passed
@ordabayevy ordabayevy deleted the param-store-types branch October 4, 2023 22:18
@ordabayevy ordabayevy mentioned this pull request Feb 5, 2024
23 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants