Skip to content

Crash related to partial type in subclass #4552

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
JukkaL opened this issue Feb 8, 2018 · 1 comment · Fixed by #6766
Closed

Crash related to partial type in subclass #4552

JukkaL opened this issue Feb 8, 2018 · 1 comment · Fixed by #6766

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Feb 8, 2018

Mypy crashes when type checking this program:

class A:
    x: str

class B(A):
    x = None
    x = ''

Here's the traceback:

Traceback (most recent call last):
  File "/Users/jukka/src/mypy/scripts/mypy", line 6, in <module>
    main(__file__)
  File "/Users/jukka/src/mypy/mypy/main.py", line 80, in main
    type_check_only(sources, bin_dir, options, flush_errors)
  File "/Users/jukka/src/mypy/mypy/main.py", line 129, in type_check_only
    flush_errors=flush_errors)
  File "/Users/jukka/src/mypy/mypy/build.py", line 173, in build
    result = _build(sources, options, alt_lib_path, bin_dir, saved_cache, flush_errors)
  File "/Users/jukka/src/mypy/mypy/build.py", line 259, in _build
    graph = dispatch(sources, manager)
  File "/Users/jukka/src/mypy/mypy/build.py", line 2094, in dispatch
    process_graph(graph, manager)
  File "/Users/jukka/src/mypy/mypy/build.py", line 2395, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/Users/jukka/src/mypy/mypy/build.py", line 2579, in process_stale_scc
    graph[id].type_check_first_pass()
  File "/Users/jukka/src/mypy/mypy/build.py", line 1951, in type_check_first_pass
    self.type_checker().check_first_pass()
  File "/Users/jukka/src/mypy/mypy/checker.py", line 229, in check_first_pass
    self.accept(d)
  File "/Users/jukka/src/mypy/mypy/checker.py", line 324, in accept
    stmt.accept(self)
  File "/Users/jukka/src/mypy/mypy/nodes.py", line 704, in accept
    return visitor.visit_class_def(self)
  File "/Users/jukka/src/mypy/mypy/checker.py", line 1252, in visit_class_def
    self.accept(defn.defs)
  File "/Users/jukka/src/mypy/mypy/checker.py", line 324, in accept
    stmt.accept(self)
  File "/Users/jukka/src/mypy/mypy/nodes.py", line 766, in accept
    return visitor.visit_block(self)
  File "/Users/jukka/src/mypy/mypy/checker.py", line 1372, in visit_block
    self.accept(s)
  File "/Users/jukka/src/mypy/mypy/checker.py", line 324, in accept
    stmt.accept(self)
  File "/Users/jukka/src/mypy/mypy/nodes.py", line 810, in accept
    return visitor.visit_assignment_stmt(self)
  File "/Users/jukka/src/mypy/mypy/checker.py", line 1379, in visit_assignment_stmt
    self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None, s.new_syntax)
  File "/Users/jukka/src/mypy/mypy/checker.py", line 1412, in check_assignment
    if self.check_compatibility_all_supers(lvalue, lvalue_type, rvalue):
  File "/Users/jukka/src/mypy/mypy/checker.py", line 1513, in check_compatibility_all_supers
    base_node):
  File "/Users/jukka/src/mypy/mypy/checker.py", line 1571, in check_compatibility_super
    'base class "%s" defined the type as' % base.name())
  File "/Users/jukka/src/mypy/mypy/checker.py", line 2961, in check_subtype
    if is_subtype(subtype, supertype):
  File "/Users/jukka/src/mypy/mypy/subtypes.py", line 83, in is_subtype
    ignore_declared_variance=ignore_declared_variance))
  File "/Users/jukka/src/mypy/mypy/types.py", line 1292, in accept
    return visitor.visit_partial_type(self)
  File "/Users/jukka/src/mypy/mypy/subtypes.py", line 349, in visit_partial_type
    raise RuntimeError
RuntimeError:

We can fix this issue by checking the compatibility of attributes with base classes at the end of type checking a class.

@ilevkivskyi
Copy link
Member

Currently this crash happens only with --no-strict-optional.

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.

3 participants