Add --check-untyped-defs to mypy.ini and test suite#37594
Add --check-untyped-defs to mypy.ini and test suite#37594rgommers wants to merge 9 commits intopytorch:masterfrom
Conversation
Also move the ignores for imports to the bottom in mypy.ini, those are much less interesting - start with the stuff people want to work on.
| 2. Inline type annotations for all Python code, _except_ if there are too many | ||
| overloads for functions/methods - in that case a stub file should be | ||
| preferred (what's too many is a bit of a judgement call, I'd suggest two per | ||
| function is a reasonable threshold). |
There was a problem hiding this comment.
One of the benefits of type hints is that they are self-documenting. For this reason, I'd personally be a bit more aggressive in the number of permissible @overloads permitted before going to stubs. Unfortunately, I don't have a firm number in mind.
If feasible, what might be beneficial is an analysis of the distribution of @overloads per function/method to inform the decision.
There was a problem hiding this comment.
Right now I don't see any that exceed the threshold. torch/nn/modules/container.pyi has some double overloads (__init__, __getitem__). I expect the number of overloads to grow significantly though when people want to make signatures more specific - things like Union[Iterable[Tensor], Iterable[dict]] and Union[int, List[int], Size] may turn into overloads.
That said, point taken, I'll bump it to 3.
There was a problem hiding this comment.
#35566 is another case where we may not be able to put things in code, and have to move it to stubs.
|
This LGTM. @rgommers I'll let you make the small updates first? Another place these docs could live is in the wiki, where you don't have to go through landing cycle as is the case in the main repo. |
yep
That makes sense to me. I only used this because |
SGTM! |
💊 Build failures summary and remediationsAs of commit 4c6fa06 (more details on the Dr. CI page):
🕵️ 1 new failure recognized by patternsThe following build failures do not appear to be due to upstream breakages:
|
facebook-github-bot
left a comment
There was a problem hiding this comment.
@ezyang is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
|
While finishing the "task list" for completing the type annotations I found it was better to add The guide of how to add type annotations and ~180 tasks for it are now in https://github.com/pytorch/pytorch/wiki/Guide-for-adding-type-annotations-to-PyTorch. Please have a look at that as well if you see any fundamental problem. I think when this PR is merged we're good to start tackling those tasks. |
Summary: Also move the ignores for imports to the bottom in `mypy.ini`, those are much less interesting - start with the stuff people want to work on. Second commit tests the instructions: remove an ignore, fix the issue. Pull Request resolved: pytorch#37594 Differential Revision: D21434858 Pulled By: ezyang fbshipit-source-id: 4f1a6868cdb4cb59d072bcf105f48c3a5ba3ff98
Also move the ignores for imports to the bottom in
mypy.ini, those are much less interesting - start with the stuff people want to work on.Second commit tests the instructions: remove an ignore, fix the issue.