FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Overriding definition such as type alias in a subclass causes a crash · Issue #5425 · python/mypy · GitHub

Repository navigation

Overriding definition such as type alias in a subclass causes a crash #5425

Closed

Description

The following program crashes on both mypy 0.620 and the latest version on master:

from typing import Any, Callable

class Parent:
    foo = Callable[..., int] 

class Child(Parent):
    def foo(self, val: int) -> int:
        return val * 2

(In this case, I meant to do foo: Callable[..., int].)

Here's the traceback:

test.py:13: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/
issues version: 0.630+dev-1222c9637b673bcca6218a943cd4b88b8749b0ad
Traceback (most recent call last):
  File "C:\Python3.6\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Python3.6\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\Michael\Dropbox\mypy\mypy\__main__.py", line 11, in <module>
    main(None)
  File "C:\Users\Michael\Dropbox\mypy\mypy\main.py", line 91, in main
    res = type_check_only(sources, bin_dir, options, flush_errors, fscache)  # noqa
  File "C:\Users\Michael\Dropbox\mypy\mypy\main.py", line 148, in type_check_only
    fscache=fscache)
  File "C:\Users\Michael\Dropbox\mypy\mypy\build.py", line 177, in build
    flush_errors, fscache)
  File "C:\Users\Michael\Dropbox\mypy\mypy\build.py", line 350, in _build
    graph = dispatch(sources, manager)
  File "C:\Users\Michael\Dropbox\mypy\mypy\build.py", line 2572, in dispatch
    process_graph(graph, manager)
  File "C:\Users\Michael\Dropbox\mypy\mypy\build.py", line 2866, in process_graph
    process_stale_scc(graph, scc, manager)
  File "C:\Users\Michael\Dropbox\mypy\mypy\build.py", line 2989, in process_stale_scc
    graph[id].type_check_first_pass()
  File "C:\Users\Michael\Dropbox\mypy\mypy\build.py", line 2162, in type_check_first_pass
    self.type_checker().check_first_pass()
  File "C:\Users\Michael\Dropbox\mypy\mypy\checker.py", line 253, in check_first_pass
    self.accept(d)
  File "C:\Users\Michael\Dropbox\mypy\mypy\checker.py", line 352, in accept
    stmt.accept(self)
  File "C:\Users\Michael\Dropbox\mypy\mypy\nodes.py", line 808, in accept
    return visitor.visit_class_def(self)
  File "C:\Users\Michael\Dropbox\mypy\mypy\checker.py", line 1389, in visit_class_def
    self.accept(defn.defs)
  File "C:\Users\Michael\Dropbox\mypy\mypy\checker.py", line 352, in accept
    stmt.accept(self)
  File "C:\Users\Michael\Dropbox\mypy\mypy\nodes.py", line 873, in accept
    return visitor.visit_block(self)
  File "C:\Users\Michael\Dropbox\mypy\mypy\checker.py", line 1535, in visit_block
    self.accept(s)
  File "C:\Users\Michael\Dropbox\mypy\mypy\checker.py", line 352, in accept
    stmt.accept(self)
  File "C:\Users\Michael\Dropbox\mypy\mypy\nodes.py", line 591, in accept
    return visitor.visit_func_def(self)
  File "C:\Users\Michael\Dropbox\mypy\mypy\checker.py", line 663, in visit_func_def
    self._visit_func_def(defn)
  File "C:\Users\Michael\Dropbox\mypy\mypy\checker.py", line 674, in _visit_func_def
    self.check_method_override(defn)
  File "C:\Users\Michael\Dropbox\mypy\mypy\checker.py", line 1200, in check_method_override
    self.check_method_or_accessor_override_for_base(defn, base)
  File "C:\Users\Michael\Dropbox\mypy\mypy\checker.py", line 1210, in check_method_or_accessor_override_for_base
    self.check_method_override_for_base_with_name(defn, name, base)
  File "C:\Users\Michael\Dropbox\mypy\mypy\checker.py", line 1254, in check_method_override_for_base_with_name
    assert False, str(base_attr.node)
AssertionError: <mypy.nodes.TypeAlias object at 0x000002139F12C588>
test.py:13: : note: use --pdb to drop into pdb

I did a cursory skim of the existing crash issues, but maybe this is already a known issue? If so, feel free to close.

Activity

  1. ilevkivskyi commented on Aug 7, 2018

    Member

    I think this is a new crash caused by the recent refactoring, previously type aliases were just Vars (hence the assert), but now they have a new dedicated SymbolNode. The fix is straightforward however.

  2. self-assigned this
    on Aug 7, 2018
  3. changed the title [-]Overriding a type alias in a subclass causes a crash[/-] [+]Overriding definition such as type alias in a subclass causes a crash[/+] on Sep 24, 2018
  4. JukkaL commented on Sep 24, 2018

    Collaborator

    As discussed in #5662, similar crashes are possible for other kinds of overrides. We should verify that all combinations of base class / subclass node types are handled correctly, including these:

    • Variable
    • Method
    • Type alias
    • Type variable
    • Class definition
    • Module reference
    • Other special assignments (new type, named tuple, typed dict)
  5. pdeblanc commented on Apr 21, 2019

    I have an example for a crash on a trivial override (i.e. not changing the type):

    from typing import Generic, TypeVar
    
    T = TypeVar('T')
    
    
    class Parent(Generic[T]):
        def __init__(self, value: T) -> None:
            self.value: T = value
    
    
    class Child(Parent[T]):
        def __init__(self, value: T) -> None:
            self.value: T = value
    

    Mypy:

    ➜  ~ git:(mypy-bug) ✗ mypy --version
    mypy 0.701
    ➜  ~ git:(mypy-bug) ✗ mypy foo.py --show-traceback
    foo.py:13: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.701
    Traceback (most recent call last):
      File "/usr/local/bin/mypy", line 10, in <module>
        sys.exit(console_entry())
      File "mypy/checker.py", line 395, in accept
      File "mypy/nodes.py", line 1019, in accept
      File "mypy/checker.py", line 1711, in visit_assignment_stmt__StatementVisitor_glue
      File "mypy/checker.py", line 1717, in visit_assignment_stmt
      File "mypy/checker.py", line 1777, in check_assignment
      File "mypy/checker.py", line 1880, in check_compatibility_all_supers
      File "mypy/checker.py", line 1967, in lvalue_type_from_base
    AssertionError: Internal error: base lookup outside class
    foo.py:13: : note: use --pdb to drop into pdb
    
  6. ilevkivskyi commented on Apr 25, 2019

    Member

    @pdeblanc I think what you see is a symptom of another horrible crash #5846

  7. removed their assignment
    on Dec 9, 2019
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


      Back | FazBrowse Home | New Git URL