Skip to content

Commit c703685

Browse files
author
Guido van Rossum
committed
Add a note clarifying type comments and mentioning cast().
1 parent 4825e34 commit c703685

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

docs/source/type_inference_and_annotations.rst

+6
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ type:
7878
7979
x = 1.1 # type: Union[int, str] # Error!
8080
81+
.. note::
82+
83+
The best way to think about this is that the type comment sets the
84+
type of the variable, not the type of the expression. To force the
85+
type of an expression you can use ``cast(<type>, <expression>)``.
86+
8187
Explicit types for collections
8288
******************************
8389

0 commit comments

Comments
 (0)