8000 Various doc updates by gvanrossum · Pull Request #3314 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Various doc updates #3314

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

Merged
merged 6 commits into from
May 3, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add some docs and an example for ClassVar.
This goes in the 3.6 section because it only works for Python 3.6.
  • Loading branch information
Guido van Rossum committed May 3, 2017
commit 8101de766e36b6581d58c0cb8cd42178a7a2c3fe
22 changes: 22 additions & 0 deletions docs/source/python36.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ now have type annotations using either of the two forms:

.. code-block:: python

from typing import Optionsl
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional

foo: Optional[int]
bar: List[str] = []

Expand All @@ -26,6 +27,27 @@ Mypy fully supports this syntax, interpreting them as equivalent to
foo = None # type: Optional[int]
bar = [] # type: List[str]

An additional feature defined in PEP 526 is also supported: you can
mark names intended to be used as class variables with ``ClassVar``.
In a pinch you can also use ClassVar in ``# type`` comments.
Example:

.. code-block:: python

from typing import ClassVar

class C:
x: int # instance variable
y: ClassVar[int] # class variable
z = None # type: ClassVar[int]

def foo(self) -> None:
self.x = 0 # OK
self.y = 0 # Error: Cannot assign to class variable "y" via instance

C.y = 0 # This is OK


Literal string formatting (`PEP 498 <https://www.python.org/dev/peps/pep-0498>`_)
---------------------------------------------------------------------------------

Expand Down
0