Skip to content

assigning a Tuple[int, ...] to an Iterable[int] results in builtins.None or <nothing> #4466

Closed

Description

@carljm

Bug with this code:

from typing import Iterable, Tuple
x: Iterable[int] = ()
y: Tuple[int, ...] = (1, 2, 3)
x = y
reveal_type(x)

Actual result (on mypy master, Python 3.6):

tuplebug.py:9: error: Revealed type is 'builtins.None'

Actual result with --strict-optional:

tuplebug.py:9: error: Revealed type is '<nothing>'

Expected result:

The revealed type should be Tuple[int, ...].

Via git bisect, I find that this bug was introduced recently, in #4238 (cc @elazarg, @JukkaL ).

Activity

  1. carljm commented on Jan 13, 2018

    @carljm
    MemberAuthor

    (We saw this as a regression false positive on real code, when upgrading mypy.)

  2. gvanrossum commented on Jan 13, 2018

    @gvanrossum
    Member

    Ideally we should fix this before the next mypy release (which hasn't been scheduled yet).

  3. elazarg commented on Jan 14, 2018

    @elazarg
    Contributor

    Thanks for the report.

    I'd note that the following also fails, and is important to test since Tuple[int, ...] and Tuple[int, int] are handled quite differently inside mypy:

    from typing import Iterable, Tuple
    x: Iterable[int] = ()
    y: Tuple[int, int] = (1, 2)
    x = y
    reveal_type(x)  # should be Tuple[int, int], actual 'None'/'<nothing>'

    The issue seems to be subtle.

  4. emmatyping commented on Jul 2, 2018

    @emmatyping
    Member

    @ilevkivskyi I think this is the same issue I saw in #5303. I am raising priority to high, since this was a regression and came up again (and I expect it is not an uncommon pattern).

  5. self-assigned this
    on Jul 3, 2018
  6. added a commit that references this issue on Jul 22, 2018
    3fb16a2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions