Skip to content

Revise stub-files section in docs #1658

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 1 commit into from
Jun 6, 2016
Merged
Changes from all commits
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
22 changes: 12 additions & 10 deletions docs/source/type_inference_and_annotations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -151,20 +151,22 @@ Here, the type of ``rs`` is set to ``List[int]``.
Types in stub files
*******************

Recall the introductory note about the usage of stub files (See :ref:`library-stubs`)
as an alternative approach to annotate types. Stub files are valid
Python 3 files, which mirror the python modules but leave out the
runtime logic like variable initialization, function bodies and
default arguments. For example:
:ref:`Stub files <library-stubs>` are written in normal Python 3
syntax, but generally leaving out runtime logic like variable
initializers, function bodies, and default arguments, replacing them
with ellipses.

In this example, each ellipsis ``...`` is literally written in the
stub file as three dots:

.. code-block:: python

x = ... # type: int
x = ... # type: int
def afunc(code: str) -> int: ...
def afunc(a: int, b: int=...) -> int: pass

The literal ``...`` is all that's necessary!
def afunc(a: int, b: int=...) -> int: ...

.. note::

The ``...`` is also used with a different meaning in the :ref:`Callable <callable-types>` and :ref:`Tuple <tuple-types>` types.
The ellipsis ``...`` is also used with a different meaning in
:ref:`callable types <callable-types>` and :ref:`tuple types
<tuple-types>`.