Skip to content
Open
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
9 changes: 8 additions & 1 deletion docs/source/dynamic_typing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ versa).
dyn = 'x' # OK

num = dyn # No error, mypy will let you assign a value of type Any to any variable
num += 1 # Oops, mypy still thinks num is an int
num.nonexistent() # OK, num is now treated as Any in expressions
num = 'x' # Still an error: assignments are checked against the inferred int type

Assigning an ``Any`` value to a variable without an explicit annotation makes
subsequent expressions involving that variable dynamically typed. Mypy still
checks later assignments against the type inferred from the variable's original
assignment. Add an explicit annotation if you want the variable's declared type
to remain in effect after assigning an ``Any`` value.

You can think of ``Any`` as a way to locally disable type checking.
See :ref:`silencing-type-errors` for other ways you can shut up
Expand Down
Loading