Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
JukkaL opened this issue Apr 3, 2019 · 4 comments
Closed

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

JukkaL opened this issue Apr 3, 2019 · 4 comments

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Apr 3, 2019

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.

@ilevkivskyi
Copy link
Member

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

@ilevkivskyi
Copy link
Member

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

@msullivan
Copy link
Collaborator

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

@ilevkivskyi
Copy link
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
Projects
None yet
Development

No branches or pull requests

3 participants