Skip to content

wrong inference with nested unpacking #21485

@JanEricNitschke

Description

@JanEricNitschke

Bug Report

Unpacking a list into multiple variables when the list itself is (partially) created by unpacking another iterable the type inference is faulty

To Reproduce

from typing import reveal_type
text = "some\nstuff"
version, desc, *_ = [*text.split(sep="\n", maxsplit=1), None, None]
reveal_type(version)  # str
reveal_type(desc)      # None

Expected Behavior

Mypy infers version and desc and str | None (if you want to go very far you can even infer version as str because str.split never returns an empty list, but that is not my expectation)

Actual Behavior

Mypy infers version as str and desc as None

Your Environment

Mypy playground: https://mypy-play.net/?mypy=latest&python=3.12&flags=strict%2Cstrict-bytes%2Ccheck-untyped-defs%2Cdisallow-any-decorated%2Cdisallow-any-expr%2Cdisallow-any-explicit%2Cdisallow-any-generics%2Cdisallow-any-unimported%2Cdisallow-incomplete-defs%2Cdisallow-subclassing-any%2Cdisallow-untyped-calls%2Cdisallow-untyped-decorators%2Cdisallow-untyped-defs%2Cno-implicit-reexport%2Cno-strict-optional%2Cstrict-equality%2Cstrict-equality-for-none%2Cwarn-incomplete-stub%2Cwarn-redundant-casts%2Cwarn-return-any%2Cwarn-unreachable%2Cwarn-unused-configs%2Cwarn-unused-ignores%2Cextra-checks

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions