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 check_method_override_for_base_with_name #2998

Closed
jabdoa2 opened this issue Mar 14, 2017 · 6 comments
Closed

Internal error in check_method_override_for_base_with_name #2998

jabdoa2 opened this issue Mar 14, 2017 · 6 comments
Labels

Comments

@jabdoa2
Copy link

jabdoa2 commented Mar 14, 2017

We get an internal error in mypy 0.501 (latest from pip):

myfile.py:270: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues
Traceback (most recent call last):
  File "/usr/lib/python3.4/runpy.py", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.4/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.4/dist-packages/mypy/__main__.py", line 5, in <module>
    main(None)
  File "/usr/local/lib/python3.4/dist-packages/mypy/main.py", line 42, in main
    res = type_check_only(sources, bin_dir, options)
  File "/usr/local/lib/python3.4/dist-packages/mypy/main.py", line 86, in type_check_only
    options=options)
  File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 183, in build
    dispatch(sources, manager)
  File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 1531, in dispatch
    process_graph(graph, manager)
  File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 1768, in process_graph
    process_stale_scc(graph, scc)
  File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 1847, in process_stale_scc
    graph[id].type_check_first_pass()
  File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 1453, in type_check_first_pass
    self.type_checker.check_first_pass()
  File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 167, in check_first_pass
    self.accept(d)
  File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 233, in accept
    stmt.accept(self)
  File "/usr/local/lib/python3.4/dist-packages/mypy/nodes.py", line 717, in accept
    return visitor.visit_class_def(self)
  File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 970, in visit_class_def
    self.accept(defn.defs)
  File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 233, in accept
    stmt.accept(self)
  File "/usr/local/lib/python3.4/dist-packages/mypy/nodes.py", line 778, in accept
    return visitor.visit_block(self)
  File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 1063, in visit_block
    self.accept(s)
  File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 233, in accept
    stmt.accept(self)
  File "/usr/local/lib/python3.4/dist-packages/mypy/nodes.py", line 601, in accept
    return visitor.visit_decorator(self)
  File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 2052, in visit_decorator
    e.func.accept(self)
  File "/usr/local/lib/python3.4/dist-packages/mypy/nodes.py", line 536, in accept
    return visitor.visit_func_def(self)
  File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 425, in visit_func_def
    self.check_method_override(defn)
  File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 836, in check_method_override
    self.check_method_or_accessor_override_for_base(defn, base)
  File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 846, in check_method_or_accessor_override_for_base
    self.check_method_override_for_base_with_name(defn, name, base)
  File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 874, in check_method_override_for_base_with_name
    assert False, str(base_attr.node)
AssertionError: Var(config)

Code at the reported line:

    @property
    def config(self) -> Dict[str, Any]:
        """Return the merged config."""
        config = copy.deepcopy(self._driver.config)
        for name, item in self._config_overwrite.items():
            if item is not None:
                config[name] = item

        return config
@JelleZijlstra
Copy link
Member

Which line is line 270?

@jabdoa2
Copy link
Author

jabdoa2 commented Mar 14, 2017

The def line. Removing the return type does not help here.

@JelleZijlstra
Copy link
Member

Looks like this is in a branch where a base class defines the same name, but the type of the attribute on the base class is None. Not sure when that would happen.

Can you provide a small test case that reproduces the error? You'd probably need the base class of the class that triggers the error.

@jabdoa2
Copy link
Author

jabdoa2 commented Mar 14, 2017

The baseclass defines config as property. This might trigger the error. Can try to write a test case tomorrow

@JelleZijlstra
Copy link
Member

Thanks! I tried a couple of variations on that but couldn't reproduce.

@jabdoa2
Copy link
Author

jabdoa2 commented Mar 15, 2017

Minimal "working" example:

from typing import Any, Dict

class A():

    def __init__(self) -> None:
        self.config = dict()    # no annotation here


class B(A):

    @property
    def config(self) -> Dict[str, Any]:
        return {"a": 7}

Results in this stack trace:

$ python3 -m mypy --show-traceback test.py 
test.py:7: error: Need type annotation for variable
test.py:12: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues
Traceback (most recent call last):
  File "/usr/lib/python3.4/runpy.py", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.4/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.4/dist-packages/mypy/__main__.py", line 5, in <module>
    main(None)
  File "/usr/local/lib/python3.4/dist-packages/mypy/main.py", line 42, in main
    res = type_check_only(sources, bin_dir, options)
  File "/usr/local/lib/python3.4/dist-packages/mypy/main.py", line 86, in type_check_only
    options=options)
  File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 183, in build
    dispatch(sources, manager)
  File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 1531, in dispatch
    process_graph(graph, manager)
  File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 1768, in process_graph
    process_stale_scc(graph, scc)
  File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 1847, in process_stale_scc
    graph[id].type_check_first_pass()
  File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 1453, in type_check_first_pass
    self.type_checker.check_first_pass()
  File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 167, in check_first_pass
    self.accept(d)
  File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 233, in accept
    stmt.accept(self)
  File "/usr/local/lib/python3.4/dist-packages/mypy/nodes.py", line 717, in accept
    return visitor.visit_class_def(self)
  File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 970, in visit_class_def
    self.accept(defn.defs)
  File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 233, in accept
    stmt.accept(self)
  File "/usr/local/lib/python3.4/dist-packages/mypy/nodes.py", line 778, in accept
    return visitor.visit_block(self)
  File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 1063, in visit_block
    self.accept(s)
  File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 233, in accept
    stmt.accept(self)
  File "/usr/local/lib/python3.4/dist-packages/mypy/nodes.py", line 601, in accept
    return visitor.visit_decorator(self)
  File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 2052, in visit_decorator
    e.func.accept(self)
  File "/usr/local/lib/python3.4/dist-packages/mypy/nodes.py", line 536, in accept
    return visitor.visit_func_def(self)
  File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 425, in visit_func_def
    self.check_method_override(defn)
  File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 836, in check_method_override
    self.check_method_or_accessor_override_for_base(defn, base)
  File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 846, in check_method_or_accessor_override_for_base
    self.check_method_override_for_base_with_name(defn, name, base)
  File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 874, in check_method_override_for_base_with_name
    assert False, str(base_attr.node)
AssertionError: Var(config)
test.py:12: note: use --pdb to drop into pdb

Indeed when I fix the first error test.py:7: error: Need type annotation for variable this turns into this:

$ python3 -m mypy --show-traceback test.py 
test.py:13: error: Signature of "config" incompatible with supertype "A"

Which I would argue should not be an error because the getter returns exactly the same type:

from typing import Any, Dict


class A():

    def __init__(self) -> None:
        self.config = dict()    # type: Dict[str, Any]


class B(A):

    @property
    def config(self) -> Dict[str, Any]:
        return {"a": 7}

But that might be another issue

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

3 participants