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

bug: Mypy crashes upon using class-constructor with named-tuple #6524

Closed
savil opened this issue Mar 7, 2019 · 3 comments
Closed

bug: Mypy crashes upon using class-constructor with named-tuple #6524

savil opened this issue Mar 7, 2019 · 3 comments

Comments

@savil
Copy link

savil commented Mar 7, 2019

Please provide more information to help us understand the issue:

  • Are you reporting a bug, or opening a feature request?

A bug

  • Please insert below the code you are checking with mypy,
    or a mock-up repro if the source is private. We would appreciate
    if you try to simplify your case to a minimal repro.

code:

$ cat src/main.py

from typing import NamedTuple, Type, TypeVar

class NodeDataTuple(NamedTuple):
    created: int
    updated: int

T = TypeVar('T', bound=NodeDataTuple)
class Node():
    def __init__(self, data_constructor: Type[T]) -> None:
        my_dict = {"foo": "bar"}
        self._data = data_constructor(**my_dict)
  • What is the actual behavior/output?
src/main.py:11: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.670
src/main.py:11: : note: please use --show-traceback to print a traceback when reporting a bug
  • What is the behavior/output you expect?

don't crash

  • What are the versions of mypy and Python you are using?
    Do you see the same issue after installing mypy from Git master?
Environment (Mac OSX 10.14.3, in a virtualenv):
$ python --version
Python 3.7.2
$ mypy --version
mypy 0.670

Also, tried with latest git mypy version: 0.680+dev.892b8d85afb80c9833248f2a8acf1c65023e0cad

  • What are the mypy flags you are using? (For example --strict-optional)

none, no config file either

  • If mypy crashed with a traceback, please paste
    the full traceback below.
Traceback (most recent call last):
  File "/Users/savil/code/mypy-debug/venv/bin/mypy", line 10, in <module>
    sys.exit(console_entry())
  File "/Users/savil/code/mypy-debug/venv/lib/python3.7/site-packages/mypy/__main__.py", line 7, in console_entry
    main(None)
  File "/Users/savil/code/mypy-debug/venv/lib/python3.7/site-packages/mypy/main.py", line 91, in main
    res = build.build(sources, options, None, flush_errors, fscache)
  File "/Users/savil/code/mypy-debug/venv/lib/python3.7/site-packages/mypy/build.py", line 162, in build
    result = _build(sources, options, alt_lib_path, flush_errors, fscache)
  File "/Users/savil/code/mypy-debug/venv/lib/python3.7/site-packages/mypy/build.py", line 217, in _build
    graph = dispatch(sources, manager)
  File "/Users/savil/code/mypy-debug/venv/lib/python3.7/site-packages/mypy/build.py", line 2360, in dispatch
    process_graph(graph, manager)
  File "/Users/savil/code/mypy-debug/venv/lib/python3.7/site-packages/mypy/build.py", line 2660, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/Users/savil/code/mypy-debug/venv/lib/python3.7/site-packages/mypy/build.py", line 2767, in process_stale_scc
    graph[id].type_check_first_pass()
  File "/Users/savil/code/mypy-debug/venv/lib/python3.7/site-packages/mypy/build.py", line 1919, in type_check_first_pass
    self.type_checker().check_first_pass()
  File "/Users/savil/code/mypy-debug/venv/lib/python3.7/site-packages/mypy/checker.py", line 282, in check_first_pass
    self.accept(d)
  File "/Users/savil/code/mypy-debug/venv/lib/python3.7/site-packages/mypy/checker.py", line 393, in accept
    stmt.accept(self)
  File "/Users/savil/code/mypy-debug/venv/lib/python3.7/site-packages/mypy/nodes.py", line 846, in accept
    return visitor.visit_class_def(self)
  File "/Users/savil/code/mypy-debug/venv/lib/python3.7/site-packages/mypy/checker.py", line 1537, in visit_class_def
    self.accept(defn.defs)
  File "/Users/savil/code/mypy-debug/venv/lib/python3.7/site-packages/mypy/checker.py", line 393, in accept
    stmt.accept(self)
  File "/Users/savil/code/mypy-debug/venv/lib/python3.7/site-packages/mypy/nodes.py", line 911, in accept
    return visitor.visit_block(self)
  File "/Users/savil/code/mypy-debug/venv/lib/python3.7/site-packages/mypy/checker.py", line 1701, in visit_block
    self.accept(s)
  File "/Users/savil/code/mypy-debug/venv/lib/python3.7/site-packages/mypy/checker.py", line 393, in accept
    stmt.accept(self)
  File "/Users/savil/code/mypy-debug/venv/lib/python3.7/site-packages/mypy/nodes.py", line 606, in accept
    return visitor.visit_func_def(self)
  File "/Users/savil/code/mypy-debug/venv/lib/python3.7/site-packages/mypy/checker.py", line 704, in visit_func_def
    self._visit_func_def(defn)
  File "/Users/savil/code/mypy-debug/venv/lib/python3.7/site-packages/mypy/checker.py", line 708, in _visit_func_def
    self.check_func_item(defn, name=defn.name())
  File "/Users/savil/code/mypy-debug/venv/lib/python3.7/site-packages/mypy/checker.py", line 770, in check_func_item
    self.check_func_def(defn, typ, name)
  File "/Users/savil/code/mypy-debug/venv/lib/python3.7/site-packages/mypy/checker.py", line 932, in check_func_def
    self.accept(item.body)
  File "/Users/savil/code/mypy-debug/venv/lib/python3.7/site-packages/mypy/checker.py", line 393, in accept
    stmt.accept(self)
  File "/Users/savil/code/mypy-debug/venv/lib/python3.7/site-packages/mypy/nodes.py", line 911, in accept
    return visitor.visit_block(self)
  File "/Users/savil/code/mypy-debug/venv/lib/python3.7/site-packages/mypy/checker.py", line 1701, in visit_block
    self.accept(s)
  File "/Users/savil/code/mypy-debug/venv/lib/python3.7/site-packages/mypy/checker.py", line 393, in accept
    stmt.accept(self)
  File "/Users/savil/code/mypy-debug/venv/lib/python3.7/site-packages/mypy/nodes.py", line 969, in accept
    return visitor.visit_assignment_stmt(self)
  File "/Users/savil/code/mypy-debug/venv/lib/python3.7/site-packages/mypy/checker.py", line 1709, in visit_assignment_stmt
    self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None, s.new_syntax)
  File "/Users/savil/code/mypy-debug/venv/lib/python3.7/site-packages/mypy/checker.py", line 1828, in check_assignment
    in_final_declaration=inferred.is_final,
  File "/Users/savil/code/mypy-debug/venv/lib/python3.7/site-packages/mypy/checkexpr.py", line 3188, in accept
    typ = node.accept(self)
  File "/Users/savil/code/mypy-debug/venv/lib/python3.7/site-packages/mypy/nodes.py", line 1446, in accept
    return visitor.visit_call_expr(self)
  File "/Users/savil/code/mypy-debug/venv/lib/python3.7/site-packages/mypy/checkexpr.py", line 244, in visit_call_expr
    return self.visit_call_expr_inner(e, allow_none_return=allow_none_return)
  File "/Users/savil/code/mypy-debug/venv/lib/python3.7/site-packages/mypy/checkexpr.py", line 314, in visit_call_expr_inner
    ret_type = self.check_call_expr_with_callee_type(callee_type, e, fullname, object_type)
  File "/Users/savil/code/mypy-debug/venv/lib/python3.7/site-packages/mypy/checkexpr.py", line 658, in check_call_expr_with_callee_type
    object_type=object_type)[0]
  File "/Users/savil/code/mypy-debug/venv/lib/python3.7/site-packages/mypy/checkexpr.py", line 721, in check_call
    callable_node, arg_messages)
  File "/Users/savil/code/mypy-debug/venv/lib/python3.7/site-packages/mypy/checkexpr.py", line 695, in check_call
    object_type)
  File "/Users/savil/code/mypy-debug/venv/lib/python3.7/site-packages/mypy/checkexpr.py", line 753, in check_callable_call
    if (callee.is_type_obj() and callee.type_object().is_abstract
  File "/Users/savil/code/mypy-debug/venv/lib/python3.7/site-packages/mypy/types.py", line 925, in type_object
    assert isinstance(ret, Instance)
AssertionError:
src/main.py:11: : note: use --pdb to drop into pdb
@ilevkivskyi
Copy link
Member

I think this should be prohibited, since this is essentially the same as #6520. (cc @msullivan)

But in any case we should not crash.

@onlined
Copy link
Contributor

onlined commented Apr 12, 2019

On master, this doesn't crash anymore, after #6669 I suppose.
Instead, it gives an error:
test.py:11: error: Argument 1 to "NodeDataTuple" has incompatible type "**Dict[str, str]"; expected "int"
Is this a problem?

@ilevkivskyi
Copy link
Member

OK, this can be closed then. The rest is tracked in #5382 and #6520.

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

No branches or pull requests

3 participants