Various improvements to the Type Stubs document#846
Merged
srittau merged 1 commit intopython:masterfrom Aug 24, 2021
Merged
Conversation
* Rename "Abstract" to "Introduction" and remove fluff originally intended for the PEP. * "This PEP" -> "This document" * Remove note about the living document status. This is a given, not that it isn't a PEP anymore. * Third-party stubs are now distributed via PyPI. * Mention "# type: ignore[xxx]". * Fix indentation. * Reformulate sentence about cyclic imports. * Use type vars correctly in example. * Use new union syntax. * Remove "we" from sentence and slightly reformulate. * Clarify that "# incomplete" is mainly intended for stub authors. * Mention "X | Any" return type. Still needs to be explained.
Collaborator
Author
|
This includes most of @Akuli's comments, although a few still need to be incorporated. |
| variable annotations are preferred over type comments. | ||
| * A ``# type: ignore`` comment at the end of any line, which suppresses all type | ||
| errors in that line. | ||
| errors in that line. The type checker mypy supports suppressing certain |
Member
There was a problem hiding this comment.
If I recall correctly some other type checkers support similar constructs. A comparison table could be a useful part of the typing docs.
| Avoid ``Union`` return types, since they require ``isinstance()`` checks. | ||
| Use ``Any`` if necessary. | ||
| Avoid union return types, since they require ``isinstance()`` checks. | ||
| Use ``Any`` or ``X | Any`` if necessary. |
Member
There was a problem hiding this comment.
It would be useful to explain more about how the X | Any trick works: when should you use it? what does it do?
Collaborator
Author
There was a problem hiding this comment.
Indeed, but as this is not stubs-specific, probably in a best practices document?
JelleZijlstra
approved these changes
Aug 24, 2021
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
for the PEP.
it isn't a PEP anymore.