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

Do not leak UnboundTypes to type checking #4987

Closed
ilevkivskyi opened this issue May 1, 2018 · 1 comment · Fixed by #14159
Closed

Do not leak UnboundTypes to type checking #4987

ilevkivskyi opened this issue May 1, 2018 · 1 comment · Fixed by #14159
Labels
priority-1-normal refactoring Changing mypy's internals

Comments

@ilevkivskyi
Copy link
Member

Sometimes UnboundType leaks to type checking, this is not good because it can lead to crashes like this:

File ".../mypy/subtypes.py", line 814, in <listcomp>
if (not (is_proper_subtype(erase_type(item), erased_s) or
File ".../mypy/erasetype.py", line 25, in erase_type
return typ.accept(EraseTypeVisitor())
File ".../mypy/types.py", line 194, in accept
return visitor.visit_unbound_type(self)
File ".../mypy/erasetype.py", line 31, in visit_unbound_type
assert False, 'Not supported'
AssertionError: Not supported

It would be better to replace all UnboundTypes with Any (after an error is reported).

ilevkivskyi added a commit that referenced this issue Jun 21, 2018
)

Fixes #4543

This is also a temporary solution for #4987. A permanent one would be to turn UnboundTypes into Anys directly in semanal.py.
@ilevkivskyi ilevkivskyi removed the crash label Jun 21, 2018
@ilevkivskyi
Copy link
Member Author

Update: this doesn't crash anymore, but we still to avoid leaking UnboundTypes.

msullivan added a commit that referenced this issue Mar 17, 2020
Fixes #8511.

This is a workaround of #4987, where UnboundTypes can leak.
msullivan added a commit that referenced this issue Mar 17, 2020
Fixes #8511.

This is a workaround of #4987, where UnboundTypes can leak.
msullivan added a commit that referenced this issue Mar 17, 2020
Fixes #8511.

This is a workaround of #4987, where UnboundTypes can leak.
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
Labels
priority-1-normal refactoring Changing mypy's internals
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant