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

Ban bogus "existential types" #7084

Closed
ilevkivskyi opened this issue Jun 27, 2019 · 0 comments · Fixed by #14159
Closed

Ban bogus "existential types" #7084

ilevkivskyi opened this issue Jun 27, 2019 · 0 comments · Fixed by #14159

Comments

@ilevkivskyi
Copy link
Member

It is possible to get an unbound type variable in a variable type using a generic alias, for example:

from typing import TypeVar, Dict
  
T = TypeVar('T')
Alias = Dict[str, T]

x: Alias[T]
reveal_type(x)  # Revealed type is 'builtins.dict[builtins.str, T?]'

This doesn't makes sense currently and should give an error.

See also #6520 (this looks very similar but is actually a different issue specific to type aliases).

ilevkivskyi added a commit that referenced this issue Nov 24, 2022
Fixes #11855 
Fixes #7084
Fixes #10445
Should fix #4987

After thinking about this for some time, it looks like the best way to
implement this is by switching type aliases from unbound to bound type
variables. Then I can essentially simply share (or copy in one small
place, to avoid cyclic imports) all the logic that currently exists for
`ParamSpec` and `Concatenate` in `expand_type()` etc.

This will also address a big piece of tech debt, and will get some
benefits (almost) for free, such as checking bounds/values for alias
type variables, and much tighter handling of unbound type variables.

Note that in this PR I change logic for emitting some errors, I try to
avoid showing multiple errors for the same location/reason. But this is
not an essential part of this PR (it is just some test cases would
otherwise fail with even more error messages), I can reconsider if there
are objections.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant