-
Notifications
You must be signed in to change notification settings - Fork 7.1k
fix mypy errors after the 0.981 release #6652
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -2,7 +2,7 @@ | |||
import functools | ||||
import pathlib | ||||
import pickle | ||||
from typing import Any, BinaryIO, Callable, cast, Dict, IO, Iterator, List, Sequence, Sized, Tuple, TypeVar, Union | ||||
from typing import Any, BinaryIO, Callable, Dict, IO, Iterator, List, Sequence, Sized, Tuple, TypeVar, Union | ||||
|
||||
import torch | ||||
import torch.distributed as dist | ||||
|
@@ -72,8 +72,8 @@ def _getattr_closure(obj: Any, *, attrs: Sequence[str]) -> Any: | |||
return obj | ||||
|
||||
|
||||
def _path_attribute_accessor(path: pathlib.Path, *, name: str) -> D: | ||||
return cast(D, _getattr_closure(path, attrs=name.split("."))) | ||||
def _path_attribute_accessor(path: pathlib.Path, *, name: str) -> Any: | ||||
return _getattr_closure(path, attrs=name.split(".")) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this change needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Same as above. We no longer can use a
IIRC, this is a remnant when this function was a local one inside
In there the annotation was correct and ok, since we have a |
||||
|
||||
|
||||
def _path_accessor_closure(data: Tuple[str, Any], *, getter: Callable[[pathlib.Path], D]) -> D: | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity why do we need to change this one, and not all the other usages of
M
e.g. inregister_model()
above?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TypeVar
is used to create a "link" between parameters. For example I can do something likeThis tells
mypy
"whatever we have as input type, we return as output type as well". This is useful in case the function can handle multiple types, e.g.In the case above, there is no input with the type
M
and somypy
complains that it can't figure out theM
in the output.Correct me if I'm wrong @datumbox, but I guess the annotation was intended to mean "we return any kind of model" here. Since
M
is defined asvision/torchvision/models/_api.py
Line 168 in 06d9726
we can simply use
nn.Module
here.