Skip to content
Closed
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 section on variable type declaration
the x: List[str] = [] style of declaration is new in 3.6 and used
throughout this doc. For users who might be reading this doc and using
an older python, this section explains the older # type: List[str]
format.
  • Loading branch information
vilmibm committed May 22, 2017
commit 9a32a154e03e2a7f480e4fb52d00b4a94b65edf9
20 changes: 20 additions & 0 deletions docs/source/common_issues.rst
Original file line number Diff line number Diff line change
Expand Up @@ -440,3 +440,23 @@ Here's the above example modified to use ``MYPY``:

def listify(arg: 'bar.BarClass') -> 'List[bar.BarClass]':
return [arg]

.. _variable-types:

Variable definition type syntax
-------------------------------

If running a Python older than 3.6, the following type declaration will fail:

.. code-block:: python

x: List[str] = [] # SyntaxError: invalid syntax


You can instead use this format in older Pythons (including 2):

.. code-block:: python

x = [] # type: List[str]