-
Notifications
You must be signed in to change notification settings - Fork 308
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
Add more type annotations and improve MonkeyType tooling #600
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
3565f70
Apply monkeytype to twine.repository
bhrutledge 94603fd
Clean up after monkeytype
bhrutledge 77f748e
Apply monkeytype to twine.utils
bhrutledge 32d9a1a
Clean up after monkeytype
bhrutledge 1e8db13
Apply monkeytype to twine.package
bhrutledge 8c5907b
Clean up after monkeytype
bhrutledge 25d4d42
Apply monkeytype to twine.auth
bhrutledge d786e29
Clean up after monkeytype
bhrutledge 9ab7d6f
Add annotations to twine.settings
bhrutledge bec1ed8
Add monkeytype to tox
bhrutledge f9c395e
Apply monkeytype to twine.cli
bhrutledge 3ecec41
Clean up after monkeytype
bhrutledge c939004
Add TODOs to mypy config
bhrutledge 40acce8
Enable strict settings that already pass
bhrutledge 444c9c7
Fix incomplete defs
bhrutledge 157d93a
Fix untyped defs
bhrutledge 1d3ab55
Fix any generics
bhrutledge 174a3c5
Fix return any
bhrutledge 1695600
Add comment re: subclassing any
bhrutledge 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,32 @@ | ||
[mypy] | ||
; TODO: check_untyped_defs = True | ||
; TODO: Make this more granular; docs recommend it as a "last resort" | ||
; https://mypy.readthedocs.io/en/latest/existing_code.html#start-small | ||
; https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-type-hints-for-third-party-library | ||
ignore_missing_imports = True | ||
; NOTE: Docs recommend `normal` or `silent` for an existing codebase | ||
; https://mypy.readthedocs.io/en/latest/running_mypy.html#following-imports | ||
; follow_imports = skip | ||
|
||
warn_redundant_casts = True | ||
warn_unused_configs = True | ||
warn_unused_ignores = True | ||
|
||
; Reporting | ||
show_traceback = True | ||
html_report = mypy | ||
linecount_report = mypy | ||
lineprecision_report = mypy | ||
txt_report = mypy | ||
|
||
; TODO: Adopt --strict settings, iterating towards something like: | ||
; https://github.com/pypa/packaging/blob/master/setup.cfg | ||
; Starting with modules that have annotations applied via MonkeyType | ||
[mypy-twine.auth,twine.cli,twine.package,twine.repository,twine.utils] | ||
; Enabling this will fail on subclasses of untype imports, e.g. tqdm | ||
; disallow_subclassing_any = True | ||
disallow_any_generics = True | ||
disallow_untyped_calls = True | ||
disallow_untyped_defs = True | ||
disallow_incomplete_defs = True | ||
check_untyped_defs = True | ||
disallow_untyped_decorators = True | ||
no_implicit_optional = True | ||
warn_return_any = True | ||
no_implicit_reexport = True | ||
strict_equality = True |
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
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
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.
Definitely a nit, but is there a reason why we're importing like this and not:
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.
Also, would be nice to avoid these imports at runtime, see what the
packaging
library is doing here: https://github.com/pypa/packaging/blob/61672bf9f507f38e84ce2786a1c42f55fa0a3153/packaging/_typing.pyThere 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.
That's a side-effect of:
twine/.isort.cfg
Lines 2 to 3 in 2c30b1e
which was added in #576. Still waiting on an isort release that includes PyCQA/isort#1085.
I've seen the
if TYPE_CHECKING
pattern before, but never investigated why it was useful. From thepackaging
link (emphasis mine):My read on this is that
if TYPE_CHECKING
is useful for Py2/3 compatibility, which Twine doesn't need. The mypy docs also include examples of using it for troubleshooting, e.g. import cycles.So, I'm happy to add it if it's valuable, but it's not clear to me how it would be.
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.
Okay, so if I understand this correctly, as per the google style guide , we are allowed to import multiple specific classes on one line from the typing module.
But there is currently no support from isort in the version we are using to globally force single line imports, but exclude certain modules from that rule, which is what
single_line_exclusions=typing
would do in a newer version of isort once PyCQA/isort#1085 is mergedThere 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.
@deveshks That's correct.
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.
@di I'm going to merge this as-is, but I'd love to hear your thoughts about
TYPE_CHECKING
.Also: I really enjoyed your Static Typing talk.