-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Add infrastructure support for static type-checking using mypy #4545
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
0f9d259
Add basic mypy support
pradyunsg bc637a8
:newspaper:
pradyunsg ed9208e
Improve mypy configuration
pradyunsg 9fce241
Patch pkg_resources for mypy
pradyunsg 8f92b55
Fix mypy warnings
pradyunsg da46ab2
Add type annotations to pip.configuration
pradyunsg 711596b
Use pip.utils.typing to guard typing imports
pradyunsg 7c5f901
Modify vendoring to include additional .pyi stubs
pradyunsg adf4538
Add generated stubs
pradyunsg c2371a1
Exclude the pyi files and extra directory created
pradyunsg b3e16f9
Fix mypy errors since addition of stubs
pradyunsg 55fd83f
Add a separate tox job for mypy
pradyunsg 6a0da3d
Fix a bug found by mypy
pradyunsg 9b03434
use six instead of try except
pradyunsg 3046f7a
Don't ask for permission
pradyunsg 182c548
Fix remaining errors
pradyunsg b9b5e4a
:art:
pradyunsg 1b5a23f
:wrench:
pradyunsg c365304
Merge branch 'master' into mypy/infrastructure
pradyunsg cb113d5
I actually missed a conflict. Wow.
pradyunsg 11451c5
Merge branch 'master' into mypy/infrastructure
pradyunsg d37868f
Move the typing file
pradyunsg d408818
Add imports I'd missed
pradyunsg d9a4431
Move mypy stubs as well
pradyunsg efd7264
Update MANIFEST
pradyunsg ec26f0a
Import from inner packages
pradyunsg da57810
type: Any partials in cmdoptions
pradyunsg 93d9f20
Remove a useless section
pradyunsg e2b2f70
isort all imports
pradyunsg 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
Merge branch 'master' into mypy/infrastructure
- Loading branch information
commit c365304f66ac9e87a02f854f81e6e280ccaf16ad
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 +1 @@ | ||
| Upgraded pkg_resources (via setuptools) to 35.0.2. | ||
| Upgraded pkg_resources (via setuptools) to 36.2.6. |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import os | ||
| import errno | ||
| import sys | ||
|
|
||
|
|
||
| def _makedirs_31(path, exist_ok=False): | ||
| try: | ||
| os.makedirs(path) | ||
| except OSError as exc: | ||
| if not exist_ok or exc.errno != errno.EEXIST: | ||
| raise | ||
|
|
||
|
|
||
| # rely on compatibility behavior until mode considerations | ||
| # and exists_ok considerations are disentangled. | ||
| # See https://github.com/pypa/setuptools/pull/1083#issuecomment-315168663 | ||
| needs_makedirs = ( | ||
| sys.version_info < (3, 2, 5) or | ||
| (3, 3) <= sys.version_info < (3, 3, 6) or | ||
| (3, 4) <= sys.version_info < (3, 4, 1) | ||
| ) | ||
| makedirs = _makedirs_31 if needs_makedirs else os.makedirs |
This file contains hidden or 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,3 +1,3 @@ | ||
| from .core import TomlError | ||
| from .parser import load, loads | ||
| from .writer import dump, dumps | ||
| from .core import TomlError | ||
| from .parser import load, loads | ||
| from .writer import dump, dumps |
This file contains hidden or 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,13 @@ | ||
| class TomlError(RuntimeError): | ||
| def __init__(self, message, line, col, filename): | ||
| RuntimeError.__init__(self, message, line, col, filename) | ||
| self.message = message | ||
| self.line = line | ||
| self.col = col | ||
| self.filename = filename | ||
| def __str__(self): | ||
| return '{}({}, {}): {}'.format(self.filename, self.line, self.col, self.message) | ||
| def __repr__(self): | ||
| return 'TomlError({!r}, {!r}, {!r}, {!r})'.format(self.message, self.line, self.col, self.filename) | ||
| class TomlError(RuntimeError): | ||
| def __init__(self, message, line, col, filename): | ||
| RuntimeError.__init__(self, message, line, col, filename) | ||
| self.message = message | ||
| self.line = line | ||
| self.col = col | ||
| self.filename = filename | ||
|
|
||
| def __str__(self): | ||
| return '{}({}, {}): {}'.format(self.filename, self.line, self.col, self.message) | ||
|
|
||
| def __repr__(self): | ||
| return 'TomlError({!r}, {!r}, {!r}, {!r})'.format(self.message, self.line, self.col, self.filename) |
Oops, something went wrong.
You are viewing a condensed version of this merge commit. You can view the full changes here.
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.
This bothers me, because we don't normally modify vendored files. But I guess it's needed to stop mypy complaining about the pkg_resources code.
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.
I think it won't hurt to make a PR to setuptools with just this change. 🤷♂️
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.
Indeed, there's specifically a prohibition from modifying vendored files because of the inherent maintenance burden that creates. You would expect that change to get overwritten the next time the vendored library is updated.
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.
@jaraco I made pypa/setuptools#1092 a few days back. :)
Uh oh!
There was an error while loading. Please reload this page.
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.
Umm... It's been added to a patch that pip can apply on the vendored package. So, it would get updated but it's still fragile because the patch breaks if the line numbers change.