Skip to content

Update documentation of ClassVar - #6005

Merged
JukkaL merged 2 commits into
masterfrom
doc-classvar
Dec 4, 2018
Merged

JukkaL merged 2 commits into
masterfrom
doc-classvar

Conversation

@JukkaL

@JukkaL JukkaL commented Dec 4, 2018

Copy link
Copy Markdown
Collaborator

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.
@JukkaL
JukkaL requested a review from gvanrossum December 4, 2018 17:19

@gvanrossum gvanrossum left a comment

Copy link
Copy Markdown
Member

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.

Comment thread docs/source/class_basics.rst Outdated

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

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

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

Comment thread 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.

Copy link
Copy Markdown
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. :-)

Comment thread 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:

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

2 participants