-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
d47ede9
make mypy more strict for prototype datasets
pmeier 914ebee
Merge branch 'main' into prototype-mypy
pmeier be3babf
fix code format
pmeier be44a6e
Merge branch 'main' into prototype-mypy
pmeier b437fa3
apply strictness only to datasets
pmeier 182a4ea
fix more mypy issues
pmeier 7b14618
cleanup
pmeier 0fe36e4
Merge branch 'main' into prototype-mypy
pmeier 722dbe6
Merge branch 'main' into prototype-mypy
pmeier f7943d7
fix mnist annotations
pmeier 735e41f
refactor celeba
pmeier dc85d36
Merge branch 'main' into prototype-mypy
pmeier 1c83855
warn on redundant casts
pmeier 069d402
remove redundant cast
pmeier 2095cdb
simplify annotation
pmeier 0a954d3
fix import
pmeier 70ce129
Merge branch 'main' into prototype-mypy
pmeier 7da45d3
Merge branch 'main' into prototype-mypy
pmeier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.