Skip to content
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

Merged
merged 2 commits into from Dec 4, 2018
Merged

Update documentation of ClassVar #6005

merged 2 commits into from Dec 4, 2018

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented 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.

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.
Copy link
Member

@gvanrossum gvanrossum left a 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.

@@ -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
Copy link
Member

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).

.. note::

If you need to support Python 3.5.2 or earlier, you have to import
``ClassVar`` from ``typing_extensions`` instead (available on PyPI).
Copy link
Member

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.

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.
Copy link
Member

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. :-)

This behavior will likely change in the future, since it's surprising.

.. note::
A ``ClassVar`` type parameter cannot include any type variables:
Copy link
Member

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.

@JukkaL JukkaL merged commit 0e1c3b4 into master 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.
@JukkaL JukkaL mentioned this pull request Dec 4, 2018
@gvanrossum gvanrossum deleted the doc-classvar branch December 5, 2018 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants