File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -631,6 +631,18 @@ of the above sections.
631631 # Type of "x" is "str" here.
632632 ...
633633
634+ Function arguments are special, changing their type within function body
635+ is allowed even if they are annotated, but that annotation is used to infer
636+ types of r.h.s. of all subsequent assignments. Such middle-ground semantics
637+ provides good balance for majority of common use cases. For example:
638+
639+ .. code-block :: python
640+
641+ def process (values : list[float ]) -> None :
642+ if not values:
643+ values = [0 , 0 , 0 ]
644+ reveal_type(values) # Revealed type is list[float]
645+
634646 Note: We are planning to turn this flag on by default in a future mypy
635647 release, along with :option: `--local-partial-types <mypy --local-partial-types> `.
636648 The feature is still experimental, and the semantics may still change.
Original file line number Diff line number Diff line change @@ -748,6 +748,18 @@ section of the command line docs.
748748 # Type of "x" is "str" here.
749749 ...
750750
751+ Function arguments are special, changing their type within function body
752+ is allowed even if they are annotated, but that annotation is used to infer
753+ types of r.h.s. of all subsequent assignments. Such middle-ground semantics
754+ provides good balance for majority of common use cases. For example:
755+
756+ .. code-block :: python
757+
758+ def process (values : list[float ]) -> None :
759+ if not values:
760+ values = [0 , 0 , 0 ]
761+ reveal_type(values) # Revealed type is list[float]
762+
751763 Note: We are planning to turn this flag on by default in a future mypy
752764 release, along with :confval: `local_partial_types `.
753765
You can’t perform that action at this time.
0 commit comments