-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Update documentation of ClassVar #6005
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.
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.
You can address the nits and land without sending for another review.
docs/source/class_basics.rst
Outdated
@@ -39,7 +39,8 @@ a type annotation: | |||
a.x = [1] # OK | |||
|
|||
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 |
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'd make the parenthetical remark a separate sentence (in parentheses).
docs/source/class_basics.rst
Outdated
.. note:: | ||
|
||
If you need to support Python 3.5.2 or earlier, you have to import | ||
``ClassVar`` from ``typing_extensions`` instead (available on PyPI). |
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.
In 2.7 it's in typing.
docs/source/class_basics.rst
Outdated
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. |
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 sure hope so. I'd have put my money on int
. :-)
docs/source/class_basics.rst
Outdated
This behavior will likely change in the future, since it's surprising. | ||
|
||
.. note:: | ||
A ``ClassVar`` type parameter cannot include any type variables: |
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'd remove "any" here.
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.
This contains several changes:
super essential feature.
typing_extensions
.haven't been introduced yet.