File tree Expand file tree Collapse file tree 2 files changed +19
-7
lines changed Expand file tree Collapse file tree 2 files changed +19
-7
lines changed Original file line number Diff line number Diff line change @@ -516,9 +516,6 @@ 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
-
522
519
Example where this can be useful:
523
520
524
521
.. code-block :: python
@@ -528,7 +525,15 @@ of the above sections.
528
525
items = [item.split() for item in items]
529
526
# 'items' now has type list[list[str]]
530
527
531
- items = " mypy" # invalid redefinition to str because the expression doesn't contain a reference to 'items'
528
+ The variable must be used before it can be redefined.
529
+
530
+ .. code-block :: python
531
+
532
+ def process (items : list[str ]) -> None :
533
+ items = " mypy" # invalid redefinition to str because the variable hasn't been used yet
534
+ print (items)
535
+ items = " 100" # valid, items not has type str
536
+ items = int (items) # valid, items not has type int
532
537
533
538
.. option :: --local-partial-types
534
539
Original file line number Diff line number Diff line change @@ -613,8 +613,7 @@ section of the command line docs.
613
613
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
-
617
- The expression for the new value must contain a reference to the variable:
616
+ Example where this can be useful:
618
617
619
618
.. code-block :: python
620
619
@@ -623,7 +622,15 @@ section of the command line docs.
623
622
items = [item.split() for item in items]
624
623
# 'items' now has type list[list[str]]
625
624
626
- items = " mypy" # invalid redefinition to str because the expression doesn't contain a reference to 'items'
625
+ The variable must be used before it can be redefined.
626
+
627
+ .. code-block :: python
628
+
629
+ def process (items : list[str ]) -> None :
630
+ items = " mypy" # invalid redefinition to str because the variable hasn't been used yet
631
+ print (items)
632
+ items = " 100" # valid, items not has type str
633
+ items = int (items) # valid, items not has type int
627
634
628
635
.. confval :: local_partial_types
629
636
You can’t perform that action at this time.
0 commit comments