-
Notifications
You must be signed in to change notification settings - Fork 7k
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
make mypy more strict for prototype datasets #4513
Changes from 3 commits
d47ede9
914ebee
be3babf
be44a6e
b437fa3
182a4ea
7b14618
0fe36e4
722dbe6
f7943d7
735e41f
dc85d36
1c83855
069d402
2095cdb
0a954d3
70ce129
7da45d3
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import io | ||
from typing import cast | ||
|
||
import PIL.Image | ||
import torch | ||
|
@@ -8,4 +9,4 @@ | |
|
||
|
||
def pil(buffer: io.IOBase, mode: str = "RGB") -> torch.Tensor: | ||
return pil_to_tensor(PIL.Image.open(buffer).convert(mode.upper())) | ||
return cast(torch.Tensor, pil_to_tensor(PIL.Image.open(buffer).convert(mode.upper()))) | ||
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. Do we need to call 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. Correct. For untyped functions |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
|
||
|
||
# FIXME | ||
def compute_sha256(_) -> str: | ||
def compute_sha256(path: pathlib.Path) -> str: | ||
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. lol I'm afraid to ask 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. This file needs heavy refactoring as soon as the |
||
return "" | ||
|
||
|
||
|
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.
Are these the default values for those options?
If they're not the default, do we have a strong reason to use them instead of the defaults? Is this going to be clearly beneficial to the code-base and to us as developers?
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.
Nope.
Let's go through them one by one:
disallow_untyped_defs
: by defaultmypy
simply accepts untyped functions and usesAny
for the input and output annotations. If our ultimate goal is to declaretorchvision
typed, we should make sure that we don't miss some functions. This flag enforces that.no_implicit_optional
: By defaultmypy
allows this:With this option enabled, it has to be
Given that
None
is a valid input, we should also explicitly mention it in the annotation.warn_unused_ignores
: Sometimes we use# type: ignore
directives on stuff that is actually wrong in other libraries. For example fix annotation for Demultiplexer pytorch#65998 will make some ignore directives obsolete that are needed now. Without this flag, we would never know.warn_return_any
: If a function does something with dynamic types,mypy
usually falls back to treating the output asAny
. This will warn us if something like this happened, but we specified a more concrete output type.warn_unreachable
: This is more a test functionality, asmypy
will now warn us if some code is unreachable. For example, with this flag set,mypy
will warn that theif
branch is unreachable.allow_redefinition
: See Set allow_redefinition = True for mypy #4531. If we have this globally, we can of course remove it here.Apart from
warn_return_any
andwarn_unreachable
I think these flags are clearly beneficial. For the other two, they were beneficial for me in the past, but I can others object to them.