Skip to content

Commit fd32852

Browse files
committed
[docs] add more info to allow_redefinition
1 parent 6ea7cfa commit fd32852

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

docs/source/command_line.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,9 @@ of the above sections.
516516
unrelated type. This flag enables redefinition of a variable with an
517517
arbitrary type *in some contexts*: only redefinitions within the
518518
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+
519522
Example where this can be useful:
520523

521524
.. code-block:: python
@@ -524,7 +527,8 @@ of the above sections.
524527
# 'items' has type list[str]
525528
items = [item.split() for item in items]
526529
# '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'
528532
529533
.. option:: --local-partial-types
530534

docs/source/config_file.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,17 @@ section of the command line docs.
614614
Allows variables to be redefined with an arbitrary type, as long as the redefinition
615615
is in the same block and nesting level as the original definition.
616616

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+
617628
.. confval:: local_partial_types
618629

619630
:type: boolean

0 commit comments

Comments
 (0)