-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
documentationtopic-inferenceWhen to infer types or require explicit annotationsWhen to infer types or require explicit annotations
Description
mypy/docs/source/command_line.rst
Lines 636 to 639 in df05f05
.. option:: --allow-redefinition This is an older variant of :option:`--allow-redefinition-new <mypy --allow-redefinition-new>`.
mypy/docs/source/command_line.rst
Lines 644 to 646 in df05f05
We have no plans to remove this flag, but we expect that :option:`--allow-redefinition-new <mypy --allow-redefinition-new>` will replace this flag for new use cases eventually.
The flag --allow-redefinition-new added by #18727 enhances inference of new variables, as the PR description says
Infer union types for simple variables from multiple assignments, if the variable isn't annotated.
This feature is rather orthogonal to the --allow-redefinition flag. In fact,
> mypy --version
mypy 1.18.2 (compiled: yes)
> mypy redef.py --allow-redefinition
Success: no issues found in 1 source file
> mypy redef.py --allow-redefinition-new --local-partial-types
redef.py:3: error: List comprehension has incompatible type List[list[str]]; expected List[str] [misc]
Found 1 error in 1 file (checked 1 source file)
with the example in the doc of --allow-redefinition
def process(items: list[str]) -> None:
# 'items' has type list[str]
items = [item.split() for item in items]
# 'items' now has type list[list[str]]k4nar
Metadata
Metadata
Assignees
Labels
documentationtopic-inferenceWhen to infer types or require explicit annotationsWhen to infer types or require explicit annotations