Repository navigation
Fix Type Generics for VisionDataset - #9381
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/vision/9381
Note: Links to docs will display an error until the docs builds have been completed. ⏳ 1 Pending, 2 Unrelated FailuresAs of commit cd1de4f with merge base 0f6d91d ( FLAKY - The following job failed but was likely due to flakiness present on trunk:
BROKEN TRUNK - The following job failed but was present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
Hi @gabrielfruet! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
|
Thanks for the PR @gabrielfruet . I'm a bit skeptical about the added value. Can you share what kind of errors / typing issues this is preventing? |
|
Without the PR: from torch.utils.data import DataLoader
from torchvision.datasets import VisionDataset
class MyDataset(VisionDataset):
def __getitem__(self, index: int) -> tuple[Image, int]:
# Returns image and label
...
loader = DataLoader(MyDataset(...))
for batch in loader:
# Type checker thinks 'batch' is Any, not tuple[Image, int]
# No autocomplete, no type checkingWith the PR: class MyDataset(VisionDataset[tuple[Image, int]]):
def __getitem__(self, index: int) -> tuple[Image, int]:
...
loader = DataLoader(MyDataset(...))
for batch in loader:
# Type checker now knows batch is tuple[Image, int]
# Full IDE autocomplete and type checking support |
NicolasHug
left a comment
There was a problem hiding this comment.
OK, thanks for the details @gabrielfruet . Since this seems officially supported by the DataLoader, and since mypy is happy, this sounds reasonably.
|
Hey @NicolasHug! You merged this PR, but no labels were added. |
Fixes #9282
Only modified VisionDataset for simplicity.