Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions docs/source/command_line.rst
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,18 @@ of the above sections.
# Type of "x" is "str" here.
...

Function arguments are special, changing their type within function body
is allowed even if they are annotated, but that annotation is used to infer
types of r.h.s. of all subsequent assignments. Such middle-ground semantics
provides good balance for majority of common use cases. For example:

.. code-block:: python

def process(values: list[float]) -> None:
if not values:
values = [0, 0, 0]
reveal_type(values) # Revealed type is list[float]

Note: We are planning to turn this flag on by default in a future mypy
release, along with :option:`--local-partial-types <mypy --local-partial-types>`.
The feature is still experimental, and the semantics may still change.
Expand Down
12 changes: 12 additions & 0 deletions docs/source/config_file.rst
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,18 @@ section of the command line docs.
# Type of "x" is "str" here.
...

Function arguments are special, changing their type within function body
is allowed even if they are annotated, but that annotation is used to infer
types of r.h.s. of all subsequent assignments. Such middle-ground semantics
provides good balance for majority of common use cases. For example:

.. code-block:: python

def process(values: list[float]) -> None:
if not values:
values = [0, 0, 0]
reveal_type(values) # Revealed type is list[float]

Note: We are planning to turn this flag on by default in a future mypy
release, along with :confval:`local_partial_types`.

Expand Down