Skip to content

Make List[<nothing>] a subtype of List[X]? #6613

Closed

Description

@JukkaL

We could probably treat List[<nothing>] as a subtype of List[X] without significant unsafety if we ensure that no variables will be inferred with List[<nothing>] types, and List[<nothing>] can't be used as a declared type. This was discussed elsewhere a while ago. With this restriction, you can't easily perform mutation operations on an empty list that would also be used as a value in another context, since all values are usually temporaries. (Yes it's easy enough to construct an example where this is still unsafe, but these seem very unlikely to happen in real code).

#6572 is an example that this could be useful, but this has come up in other contexts as well.

Activity

  1. ilevkivskyi commented on Apr 3, 2019

    @ilevkivskyi
    Member

    This is basically what pyre does, see discussion in python/typeshed#2817

  2. ilevkivskyi commented on Oct 18, 2019

    @ilevkivskyi
    Member

    This may be also relevant for other empty containers that are invariant, like empty dicts, see #7727

  3. msullivan commented on Dec 10, 2019

    @msullivan
    Collaborator

    If this enables fixing the get type in typeshed, then I think it would fix some real world precision issues: #8123

  4. ilevkivskyi commented on Sep 27, 2023

    @ilevkivskyi
    Member

    I just merged a PR doing this, and then found this issue again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions