Skip to content

Replace comments with string literals #46

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

Closed
wants to merge 2 commits into from
Closed
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
23 changes: 14 additions & 9 deletions pep-0484.txt
Original file line number Diff line number Diff line change
Expand Up @@ -260,26 +260,28 @@ hinting, use the following:

* a ``@no_type_checks`` decorator on classes and functions

* a ``# type: ignore`` comment on arbitrary lines
* a ``'''type: ignore'''`` string literal on arbitrary lines

.. FIXME: should we have a module-wide comment as well?
.. FIXME: should we have a module-wide string literals as well?


Type Hints on Local and Global Variables
========================================

No first-class syntax support for explicitly marking variables as being
of a specific type is added by this PEP. To help with type inference in
complex cases, a comment of the following format may be used::
complex cases, a string literal of the following format may be used::

x = [] # type: List[Employee]
'''type: List[Employee]'''
x = []

In the case where type information for a local variable is needed before
if was declared, an ``Undefined`` placeholder might be used::

from typing import Undefined

x = Undefined # type: List[Employee]

'''type: List[Employee]'''
x = Undefined
y = Undefined(int)

If type hinting proves useful in general, a syntax for typing variables
Expand Down Expand Up @@ -327,9 +329,12 @@ generics and union types:
* TypeVar, used as ``X = TypeVar('X', Type1, Type2, Type3)`` or simply
``Y = TypeVar('Y')``

* Undefined, used as ``local_variable = Undefined # type: List[int]`` or
``local_variable = Undefined(List[int])`` (the latter being slower
during runtime)
* Undefined, used as ``local_variable = Undefined(List[int])`` or::

'''type: List[int]'''
local_variable = Undefined

(the former being slower during runtime)

* Callable, used as ``Callable[[Arg1Type, Arg2Type], ReturnType]``

Expand Down