File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -516,6 +516,9 @@ of the above sections.
516
516
unrelated type. This flag enables redefinition of a variable with an
517
517
arbitrary type *in some contexts *: only redefinitions within the
518
518
same block and nesting depth as the original definition are allowed.
519
+
520
+ The expression for the new value must contain a reference to the variable.
521
+
519
522
Example where this can be useful:
520
523
521
524
.. code-block :: python
@@ -524,7 +527,8 @@ of the above sections.
524
527
# 'items' has type list[str]
525
528
items = [item.split() for item in items]
526
529
# 'items' now has type list[list[str]]
527
- ...
530
+
531
+ items = " mypy" # invalid redefinition to str because the expression doesn't contain a reference to 'items'
528
532
529
533
.. option :: --local-partial-types
530
534
Original file line number Diff line number Diff line change @@ -614,6 +614,17 @@ section of the command line docs.
614
614
Allows variables to be redefined with an arbitrary type, as long as the redefinition
615
615
is in the same block and nesting level as the original definition.
616
616
617
+ The expression for the new value must contain a reference to the variable:
618
+
619
+ .. code-block :: python
620
+
621
+ def process (items : list[str ]) -> None :
622
+ # 'items' has type list[str]
623
+ items = [item.split() for item in items]
624
+ # 'items' now has type list[list[str]]
625
+
626
+ items = " mypy" # invalid redefinition to str because the expression doesn't contain a reference to 'items'
627
+
617
628
.. confval :: local_partial_types
618
629
619
630
:type: boolean
You can’t perform that action at this time.
0 commit comments