Skip to content

Conversation

@theo-m
Copy link

@theo-m theo-m commented Sep 3, 2019

Fixes #25399

As per #25580 I'm pushing this to test my changes on the CI

@theo-m theo-m requested a review from apaszke as a code owner September 3, 2019 14:58
@pytorchbot pytorchbot added module: nn Related to torch.nn module: typing Related to mypy type annotations labels Sep 3, 2019
zou3519
zou3519 previously requested changes Sep 3, 2019
@zou3519 zou3519 dismissed their stale review September 3, 2019 21:06

Mistaken

Copy link
Contributor

@zou3519 zou3519 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We didn't have a mypy check for this file before. Is it possible to add one to prevent regressions?

import builtins

class Parameter(Tensor):
def __init__(self, data: Tensor, requires_grad: builtins.bool): ...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to use builtin.bools? Does bool work?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On this I took inspiration on torch/__init__.pyi.in, without knowing the ins and outs of the decision that lead them to use this one rather than the simple bool.
Can revert to simple if need be.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In torch/__init__.pyi we cannot use bool directly because we define torch.bool, and that means that the local definition always gets picked up over the builtin. I don't know if that applies here, but it's harmless enough to use builtins.

@theo-m
Copy link
Author

theo-m commented Sep 4, 2019

We didn't have a mypy check for this file before. Is it possible to add one to prevent regressions?

I'm sure we can, but onclear on how to proceed

@theo-m theo-m requested a review from zou3519 September 9, 2019 12:28
@zou3519 zou3519 requested review from ezyang and removed request for apaszke and zou3519 September 9, 2019 12:42
@zou3519
Copy link
Contributor

zou3519 commented Sep 9, 2019

@ezyang what is our testing strategy for type hints?

@ezyang
Copy link
Contributor

ezyang commented Sep 9, 2019

The way the mypy test works is that we collect up all docblock examples, and then typecheck them to see if the usages typecheck correctly. If it makes sense to add a Parameter example here, that would be an easy way to test this particular change (but it's only one test for very many that we could have better coverage for). Another possibility is to add some more "test files" which we test type checking against.

In any case, I don't think that should block the fix here.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ezyang is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@ezyang merged this pull request in 4fac61a.

@jongwook
Copy link
Contributor

@ezyang @zou3519 Hi, parameter.pyi confuses PyCharm to think requires_grad is a required argument.

Could you consider adding =... to the requires_grad argument?

@ezyang
Copy link
Contributor

ezyang commented Jan 13, 2020

@jongwook Yes absolutely. Do you think you could submit a PR for this? Tag me as reviewer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merged module: nn Related to torch.nn module: typing Related to mypy type annotations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No type hints on nn.Parameter

7 participants