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

Internal error in overriding __getitem__ when inheriting from a dict. #7122

Closed
adamjsawicki opened this issue Jul 1, 2019 · 2 comments
Closed
Labels

Comments

@adamjsawicki
Copy link

adamjsawicki commented Jul 1, 2019

Saw #1269 but believe that's a different matter.

Encountered the following internal error:

Traceback:

$ mypy --show-traceback script.py
script.py:3: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.660
Traceback (most recent call last):
  File "/usr/local/bin/mypy", line 10, in <module>
    sys.exit(console_entry())
  File "/usr/local/lib/python3.7/site-packages/mypy/__main__.py", line 7, in console_entry
    main(None)
  File "/usr/local/lib/python3.7/site-packages/mypy/main.py", line 91, in main
    res = build.build(sources, options, None, flush_errors, fscache)
  File "/usr/local/lib/python3.7/site-packages/mypy/build.py", line 157, in build
    result = _build(sources, options, alt_lib_path, flush_errors, fscache)
  File "/usr/local/lib/python3.7/site-packages/mypy/build.py", line 212, in _build
    graph = dispatch(sources, manager)
  File "/usr/local/lib/python3.7/site-packages/mypy/build.py", line 2246, in dispatch
    process_graph(graph, manager)
  File "/usr/local/lib/python3.7/site-packages/mypy/build.py", line 2544, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/usr/local/lib/python3.7/site-packages/mypy/build.py", line 2659, in process_stale_scc
    graph[id].type_check_first_pass()
  File "/usr/local/lib/python3.7/site-packages/mypy/build.py", line 1803, in type_check_first_pass
    self.type_checker().check_first_pass()
  File "/usr/local/lib/python3.7/site-packages/mypy/checker.py", line 282, in check_first_pass
    self.accept(d)
  File "/usr/local/lib/python3.7/site-packages/mypy/checker.py", line 393, in accept
    stmt.accept(self)
  File "/usr/local/lib/python3.7/site-packages/mypy/nodes.py", line 851, in accept
    return visitor.visit_class_def(self)
  File "/usr/local/lib/python3.7/site-packages/mypy/checker.py", line 1536, in visit_class_def
    self.accept(defn.defs)
  File "/usr/local/lib/python3.7/site-packages/mypy/checker.py", line 393, in accept
    stmt.accept(self)
  File "/usr/local/lib/python3.7/site-packages/mypy/nodes.py", line 916, in accept
    return visitor.visit_block(self)
  File "/usr/local/lib/python3.7/site-packages/mypy/checker.py", line 1700, in visit_block
    self.accept(s)
  File "/usr/local/lib/python3.7/site-packages/mypy/checker.py", line 393, in accept
    stmt.accept(self)
  File "/usr/local/lib/python3.7/site-packages/mypy/nodes.py", line 614, in accept
    return visitor.visit_func_def(self)
  File "/usr/local/lib/python3.7/site-packages/mypy/checker.py", line 704, in visit_func_def
    self._visit_func_def(defn)
  File "/usr/local/lib/python3.7/site-packages/mypy/checker.py", line 708, in _visit_func_def
    self.check_func_item(defn, name=defn.name())
  File "/usr/local/lib/python3.7/site-packages/mypy/checker.py", line 770, in check_func_item
    self.check_func_def(defn, typ, name)
  File "/usr/local/lib/python3.7/site-packages/mypy/checker.py", line 931, in check_func_def
    self.accept(item.body)
  File "/usr/local/lib/python3.7/site-packages/mypy/checker.py", line 393, in accept
    stmt.accept(self)
  File "/usr/local/lib/python3.7/site-packages/mypy/nodes.py", line 916, in accept
    return visitor.visit_block(self)
  File "/usr/local/lib/python3.7/site-packages/mypy/checker.py", line 1700, in visit_block
    self.accept(s)
  File "/usr/local/lib/python3.7/site-packages/mypy/checker.py", line 393, in accept
    stmt.accept(self)
  File "/usr/local/lib/python3.7/site-packages/mypy/nodes.py", line 971, in accept
    return visitor.visit_assignment_stmt(self)
  File "/usr/local/lib/python3.7/site-packages/mypy/checker.py", line 1708, in visit_assignment_stmt
    self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None, s.new_syntax)
  File "/usr/local/lib/python3.7/site-packages/mypy/checker.py", line 1763, in check_assignment
    if self.check_compatibility_all_supers(lvalue, lvalue_type, rvalue):
  File "/usr/local/lib/python3.7/site-packages/mypy/checker.py", line 1864, in check_compatibility_all_supers
    base_type, base_node = self.lvalue_type_from_base(lvalue_node, base)
  File "/usr/local/lib/python3.7/site-packages/mypy/checker.py", line 1951, in lvalue_type_from_base
    assert self_type is not None, "Internal error: base lookup outside class"
AssertionError: Internal error: base lookup outside class
script.py:3: : note: use --pdb to drop into pdb

Minimal repro:

class Configuration(dict):
    def __init__(self, values: dict):
        self.values: dict = {}

    def __getitem__(self, key: str):
        return self.values[key.lower()]

Realized I don't need to inherit from dict for my desired functionality, but figured I'd post anyway.

@JelleZijlstra
Copy link
Member

Confirmed. The crash also happens on latest master and with either the old or the new semantic analyzer.

@ilevkivskyi
Copy link
Member

This is not related to __getitem__(), a class with only __init__() causes the same crash:

class Configuration(dict):
    def __init__(self, values: dict):
        self.values: dict = {}

I think this is a duplicate of #5846

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants