Skip to content

Assignment expression in a tuple affects earlier indices the tuple #1179

@hamdanal

Description

@hamdanal
$ cat lib.py
def fn() -> tuple[int, int]:
    i = 0
    return (i, (i := i + 1))

$ python -c 'from lib import fn; print(fn())'
(0, 1)
$ mypyc lib.py
running build_ext
building 'lib' extension
...
$ python -c 'from lib import fn; print(fn())'
(1, 1)

Notice the first element of the tuple becomes 1 instead of 0 with mypyc compiled code.

Tested on a Linux machine with Python 3.14 and mypy 1.19.1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions