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

Annotation Problem *.pyi #26673

Closed
Roffild opened this issue Sep 23, 2019 · 7 comments
Closed

Annotation Problem *.pyi #26673

Roffild opened this issue Sep 23, 2019 · 7 comments
Assignees
Labels
high priority module: typing Related to mypy type annotations triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@Roffild
Copy link
Contributor

Roffild commented Sep 23, 2019

🚀 Feature

It is difficult to control the validity of function arguments when they are in different files.
Very often the information in *.pyi does not match *.py.

class _DataLoaderIter:

I suggest using Python 2 Annotations:

def optional_unwrap (self, x, y):
   # type: (Optional [int], Optional [int]) -> int

You can expand this format to indicate in which file to place annotations.
After that, all *.pyi can be completely assembled in one script. Information will always be up to date.

cc @ezyang @gchanan @zou3519

@VitalyFedyunin VitalyFedyunin added needs research We need to decide whether or not this merits inclusion, based on research world triage review triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module labels Sep 24, 2019
@vincentqb
Copy link
Contributor

(Python 2 support will be dropped #23795)

@malmaud
Copy link
Contributor

malmaud commented Sep 30, 2019

I think everyone would be onboard to move to inline type annotations once Python 2 support is dropped. The current preference was to use stubs instead of comment-based annotations.

Was there a specific incorrect stub?

@vincentqb vincentqb added module: typing Related to mypy type annotations and removed triage review needs research We need to decide whether or not this merits inclusion, based on research world labels Sep 30, 2019
@vincentqb
Copy link
Contributor

We'll wait for Python 2 EOL, and move all annotation inline using Python 3 syntax.

@ngoldbaum
Copy link
Contributor

Was there a specific incorrect stub?

It looks like _DataLoaderIter is now called _BaseDataLoaderIter and needs to be renamed and updated in the stubs (and possibly the various subclasses need to be added as well).

More generically, there should probably be a test that checks that the stubs agree with the actual implementation, at least so long as the mypy type information is in a separate file from the implementation.

I'll go ahead and put in a pull request this afternoon that hopefully fixes the specific issue with the type stubs for _BaseDataLoaderIter, this is my first pytorch issue so bear with me :)

@ngoldbaum ngoldbaum self-assigned this Sep 30, 2019
@malmaud
Copy link
Contributor

malmaud commented Sep 30, 2019 via email

@ngoldbaum
Copy link
Contributor

I guess ultimately the issue here is that only one file -- aten/src/ATen/function_wrapper.py -- is getting type checked by the pytorch CI at the moment (see mypy-files.txt in the root of the repo). Fixing this issue in general therefore means making mypy run over the whole codebase, which is #16574, and seems like a much bigger job than the narrow issues with the _DataLoaderIter pointed out here. I think after #27105 is merged this can be closed as a dupe of #16574?

facebook-github-bot pushed a commit that referenced this issue Oct 8, 2019
Summary:
Back in April, malmaud added type annotations for `dataloader.py`. However, at about the same time, SsnL in #19228 replaced `_DataLoaderIter` with `_BaseDataLoaderIter` and two subclasses, `_SingleProcessDataLoaderIter`, and `_MultiProcessingDataLoaderIter`. However - probably because these changes happened in parallel at roughly the same time, the type stubs and several other references in the codebase were never updated to match this refactoring.

I've gone ahead and done the updates to reflect the refactoring in #19228, which fixes the specific type stub/impelementation mismatch pointed out in #26673, although not the broader problem that pytorch doesn't have a test to make sure that the `.pyi` type stub files match the real API defined in `.py` files.
Pull Request resolved: #27105

Differential Revision: D17813641

Pulled By: ezyang

fbshipit-source-id: ed7ac025c8d6ad3f298dd073347ec83bb4b6600c
@ngoldbaum
Copy link
Contributor

The specific issue pointed out here has been fixed, so I'm going to close this in favor of #16574 which tracks broader improvements to type correctness.

thiagocrepaldi pushed a commit to thiagocrepaldi/pytorch that referenced this issue Feb 4, 2020
…ch#27105)

Summary:
Back in April, malmaud added type annotations for `dataloader.py`. However, at about the same time, SsnL in pytorch#19228 replaced `_DataLoaderIter` with `_BaseDataLoaderIter` and two subclasses, `_SingleProcessDataLoaderIter`, and `_MultiProcessingDataLoaderIter`. However - probably because these changes happened in parallel at roughly the same time, the type stubs and several other references in the codebase were never updated to match this refactoring.

I've gone ahead and done the updates to reflect the refactoring in pytorch#19228, which fixes the specific type stub/impelementation mismatch pointed out in pytorch#26673, although not the broader problem that pytorch doesn't have a test to make sure that the `.pyi` type stub files match the real API defined in `.py` files.
Pull Request resolved: pytorch#27105

Differential Revision: D17813641

Pulled By: ezyang

fbshipit-source-id: ed7ac025c8d6ad3f298dd073347ec83bb4b6600c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
high priority module: typing Related to mypy type annotations triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

No branches or pull requests

5 participants