Repository navigation
Update documentation of ClassVar - #6005
Merged
Merged
Conversation
This contains several changes: * Move section to a somewhat later location, since this is not a super essential feature. * Make ClassVar documentation closer in style to the rest of the docs. * Simplify example a bit and split it into two examples. * Mention Python version requirements and `typing_extensions`. * Add cross-reference when we mention type variables, since they haven't been introduced yet.
gvanrossum
approved these changes
Dec 4, 2018
gvanrossum
left a comment
Member
There was a problem hiding this comment.
You can address the nits and land without sending for another review.
|
|
||
| As in Python generally, a variable defined in the class body can be used | ||
| as a class or an instance variable. | ||
| as a class or an instance variable (as discussed in the next section, you |
Member
There was a problem hiding this comment.
I'd make the parenthetical remark a separate sentence (in parentheses).
| .. note:: | ||
|
|
||
| If you need to support Python 3.5.2 or earlier, you have to import | ||
| ``ClassVar`` from ``typing_extensions`` instead (available on PyPI). |
| y: ClassVar = 0 # Type implicitly Any! | ||
|
|
||
| In this case the type of the attribute will be implicitly ``Any``. | ||
| This behavior will likely change in the future, since it's surprising. |
Member
There was a problem hiding this comment.
I sure hope so. I'd have put my money on int. :-)
| This behavior will likely change in the future, since it's surprising. | ||
|
|
||
| .. note:: | ||
| A ``ClassVar`` type parameter cannot include any type variables: |
gvanrossum
approved these changes
Dec 4, 2018
JukkaL
added a commit
that referenced
this pull request
Dec 4, 2018
This contains several changes: * Move section to a somewhat later location, since this is not a super essential feature. * Make ClassVar documentation closer in style to the rest of the docs. * Simplify example a bit and split it into two examples. * Mention Python version requirements and `typing_extensions`. * Add cross-reference when we mention type variables, since they haven't been introduced yet.
Closed
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.
This contains several changes:
super essential feature.
typing_extensions.haven't been introduced yet.