Skip to content

Commit 888299f

Browse files
author
Guido van Rossum
committed
Document "variable = None # type: <some_type>". Fixes #61.
1 parent 52b1ff9 commit 888299f

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pep-0484.txt

+14
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,20 @@ ellipsis::
860860

861861
stream = ... # type: IO[str]
862862

863+
In non-stub code, there is a similar special case:
864+
865+
from typing import IO
866+
867+
stream = None # type: IO[str]
868+
869+
Type checkers should not complain about this (despite the value
870+
``None`` not matching the given type), nor should they change the
871+
inferred type to ``Optional[...]`` (despite the rule that does this
872+
for annotated arguments with a default value of ``None``). The
873+
assumption here is that other code will ensure that the variable is
874+
given a value of the proper type, and all uses can assume that the
875+
variable has the given type.
876+
863877
The ``# type: ignore`` comment should be put on the line that the
864878
error refers to::
865879

0 commit comments

Comments
 (0)