Skip to content

--allow-redefinition-new does not mean "new" implementation but "new" variables #19918

@toslunar

Description

@toslunar

.. option:: --allow-redefinition
This is an older variant of
:option:`--allow-redefinition-new <mypy --allow-redefinition-new>`.

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]]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions