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

mypy: even more strict #2241

Merged
merged 6 commits into from
Aug 23, 2024
Merged

Conversation

adamjstewart
Copy link
Collaborator

Adds additional checks like warn_unreachable that revealed new bugs. And fixes those bugs!

I also played around with generics like:

from typing import TypeVar

K = TypeVar('K')
V = TypeVar('V')

# replace all dict[Any, Any] with dict[K, V]

but ran into too many issues and gave up. Maybe another day.

@adamjstewart adamjstewart added this to the 0.6.0 milestone Aug 21, 2024
@github-actions github-actions bot added datasets Geospatial or benchmark datasets transforms Data augmentation transforms dependencies Packaging and dependencies labels Aug 21, 2024
[tool.mypy]
python_version = "3.10"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This isn't particularly useful, what we really need is python/mypy#12286

@@ -473,7 +477,7 @@ def merge_samples(samples: Iterable[dict[Any, Any]]) -> dict[Any, Any]:
return collated


def unbind_samples(sample: dict[Any, Sequence[Any]]) -> list[dict[Any, Any]]:
def unbind_samples(sample: MutableMapping[Any, Any]) -> list[dict[Any, Any]]:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This should not be a sequence, this was a bug

@@ -99,7 +99,7 @@ def forward(self, batch: dict[str, Tensor]) -> dict[str, Tensor]:

# Convert boxes to default [N, 4]
if 'boxes' in batch:
batch['boxes'] = Boxes(batch['boxes']).to_tensor(mode='xyxy') # type:ignore[assignment]
batch['boxes'] = Boxes(batch['boxes']).to_tensor(mode='xyxy')
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This bug was introduced in #1082

@adamjstewart adamjstewart merged commit 95a1fec into microsoft:main Aug 23, 2024
19 checks passed
@adamjstewart adamjstewart deleted the mypy/unreachable branch August 23, 2024 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
datasets Geospatial or benchmark datasets dependencies Packaging and dependencies transforms Data augmentation transforms
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant