Skip to content

New crashes related to partial types #3986

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

Closed
gvanrossum opened this issue Sep 22, 2017 · 8 comments
Closed

New crashes related to partial types #3986

gvanrossum opened this issue Sep 22, 2017 · 8 comments

Comments

@gvanrossum
Copy link
Member

gvanrossum commented Sep 22, 2017

We recently upgraded to a newer mypy version (c000062) and are seeing new crashes. One has a traceback ending in

[...]
File "/Users/damien/src/client/.mypy/venv/lib/python3.6/site-packages/mypy/checkexpr.py", line 753, in infer_function_type_arguments_using_context
    args = infer_type_arguments(callable.type_var_ids(), ret_type, erased_ctx)
File "/Users/damien/src/client/.mypy/venv/lib/python3.6/site-packages/mypy/infer.py", line 43, in infer_type_arguments
    return solve_constraints(type_var_ids, constraints)
File "/Users/damien/src/client/.mypy/venv/lib/python3.6/site-packages/mypy/solve.py", line 52, in solve_constraints
    top = meet_types(top, c.target)
File "/Users/damien/src/client/.mypy/venv/lib/python3.6/site-packages/mypy/meet.py", line 25, in meet_types
    return t.accept(TypeMeetVisitor(s))
File "/Users/damien/src/client/.mypy/venv/lib/python3.6/site-packages/mypy/types.py", line 1287, in accept
    return visitor.visit_partial_type(self)
File "/Users/damien/src/client/.mypy/venv/lib/python3.6/site-packages/mypy/meet.py", line 288, in visit_partial_type
    assert False, 'Internal error'
AssertionError: Internal error

And the other:

  File "/Users/guido/src/server/.mypy/venv/lib/python3.6/site-packages/mypy/nodes.py", line 817, in accept
    return visitor.visit_assignment_stmt(self)
  File "/Users/guido/src/server/.mypy/venv/lib/python3.6/site-packages/mypy/checker.py", line 1307, in visit_assignment_stmt
    self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None, s.new_syntax)
  File "/Users/guido/src/server/.mypy/venv/lib/python3.6/site-packages/mypy/checker.py", line 1367, in check_assignment
    self.infer_partial_type(lvalue_type.var, lvalue, rvalue_type)
  File "/Users/guido/src/server/.mypy/venv/lib/python3.6/site-packages/mypy/checker.py", line 1833, in infer_partial_type
    self.set_inferred_type(name, lvalue, partial_type)
  File "/Users/guido/src/server/.mypy/venv/lib/python3.6/site-packages/mypy/checker.py", line 1848, in set_inferred_type
    assert lvalue.def_var is not None
AssertionError: 

I haven't investigated these nor tried to reduce them. I do have a repeatable demo of the latter.

@ilevkivskyi
Copy link
Member

Does the first crash occurs only in quick mode? It would be quite strange.

@gvanrossum
Copy link
Member Author

Hm, you're right, the first crash also happened in plain --incremental mode.

@ilevkivskyi
Copy link
Member

It looks like I have also a repro for the second crash that doesn't even require --incremental:

class C:
    x = None
    def __init__(self) -> None:
        self.x = []

@ilevkivskyi
Copy link
Member

@gvanrossum
I still can't reproduce the first crash. Do you have some more hints?

@ilevkivskyi ilevkivskyi changed the title New crashes in quick mode New incremental crashes related to partial types Sep 24, 2017
@ilevkivskyi
Copy link
Member

ilevkivskyi commented Sep 24, 2017

Bingo!

I have the repro for the first crash as well. It doesn't require --incremental

from typing import Tuple, TypeVar
T = TypeVar('T')

def f(x: T) -> Tuple[T, T]:
    ...
x = None
(x, x) = f('')

(I have found two similar scenarios with slightly different tracebacks but all related to partial types, I will add them to tests).

@ilevkivskyi ilevkivskyi changed the title New incremental crashes related to partial types New crashes related to partial types Sep 24, 2017
@ilevkivskyi
Copy link
Member

OK, I updated PR #3995 so that it fixes both these crashes and two related crash scenarios.

@gvanrossum
Copy link
Member Author

Thanks for finding repros and adding fixes! Did something change recently that caused these crashes to appear, or were we just lucky we didn't have these patterns in our codebase before?

@ilevkivskyi
Copy link
Member

Did something change recently that caused these crashes to appear, or were we just lucky we didn't have these patterns in our codebase before?

The one with def_var is new, it was introduced in one of my recent strict optional PRs where I erroneously used assert ... is not None instead of if ... is not None:. Other crashes are old.

gvanrossum pushed a commit that referenced this issue Sep 26, 2017
Fixes #3986 and two additional similar crashes on partial types.
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

2 participants