Skip to content

New crashes related to partial types #3986

Closed

Description

@gvanrossum

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.

Activity

  1. ilevkivskyi commented on Sep 22, 2017

    @ilevkivskyi
    Member

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

  2. gvanrossum commented on Sep 22, 2017

    @gvanrossum
    MemberAuthor

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

  3. ilevkivskyi commented on Sep 23, 2017

    @ilevkivskyi
    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 = []
  4. ilevkivskyi commented on Sep 24, 2017

    @ilevkivskyi
    Member

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

  5. changed the title [-]New crashes in quick mode[/-] [+]New incremental crashes related to partial types[/+] on Sep 24, 2017
  6. ilevkivskyi commented on Sep 24, 2017

    @ilevkivskyi
    Member

    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).

  7. changed the title [-]New incremental crashes related to partial types[/-] [+]New crashes related to partial types[/+] on Sep 24, 2017
  8. ilevkivskyi commented on Sep 24, 2017

    @ilevkivskyi
    Member

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

  9. gvanrossum commented on Sep 24, 2017

    @gvanrossum
    MemberAuthor

    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?

  10. ilevkivskyi commented on Sep 24, 2017

    @ilevkivskyi
    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.

  11. added a commit that references this issue on Sep 26, 2017
    c332ea0
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