Skip to content

newsemanal crash with dataclasses #6783

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
JelleZijlstra opened this issue May 6, 2019 · 2 comments
Closed

newsemanal crash with dataclasses #6783

JelleZijlstra opened this issue May 6, 2019 · 2 comments
Labels
crash semantic-analyzer Problems that happen during semantic analysis

Comments

@JelleZijlstra
Copy link
Member

This file:

from dataclasses import dataclass


@dataclass
class Function:
    function: str
    args: object

    def __init__(self, function: str, *args: object) -> None:
        self.function = function
        self.args = args


Function("x", 1, 2)

Crashes on 0.701 with:

$ mypy --new-semantic-analyzer dataclassinit.py 
dataclassinit.py: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.701
Traceback (most recent call last):
  File "/home/jelle/ans/venv/bin/mypy", line 10, in <module>
    sys.exit(console_entry())
  File "/home/jelle/ans/venv/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry
    main(None)
  File "mypy/build.py", line 1767, in __mypyc_generator_helper__
  File "mypy/newsemanal/semanal_main.py", line 294, in check_type_arguments
  File "mypy/nodes.py", line 273, in accept
  File "mypy/newsemanal/semanal_typeargs.py", line 27, in visit_mypy_file__NodeVisitor_glue
  File "mypy/newsemanal/semanal_typeargs.py", line 30, in visit_mypy_file
  File "mypy/traverser.py", line 33, in visit_mypy_file
  File "mypy/nodes.py", line 896, in accept
  File "mypy/newsemanal/semanal_typeargs.py", line 39, in visit_class_def__StatementVisitor_glue
  File "mypy/newsemanal/semanal_typeargs.py", line 41, in visit_class_def
  File "mypy/mixedtraverser.py", line 28, in visit_class_def
  File "mypy/traverser.py", line 65, in visit_class_def
  File "mypy/nodes.py", line 961, in accept
  File "mypy/newsemanal/semanal_typeargs.py", line 43, in visit_block__StatementVisitor_glue
  File "mypy/newsemanal/semanal_typeargs.py", line 45, in visit_block
  File "mypy/traverser.py", line 37, in visit_block
  File "mypy/nodes.py", line 641, in accept
  File "mypy/traverser.py", line 51, in visit_func_def__StatementVisitor_glue
  File "mypy/traverser.py", line 52, in visit_func_def
  File "mypy/newsemanal/semanal_typeargs.py", line 33, in visit_func__MixedTraverserVisitor_glue
  File "mypy/newsemanal/semanal_typeargs.py", line 37, in visit_func
  File "mypy/mixedtraverser.py", line 23, in visit_func
  File "mypy/mixedtraverser.py", line 90, in visit_optional_type
  File "mypy/types.py", line 934, in accept
  File "mypy/typetraverser.py", line 48, in visit_callable_type__TypeVisitor_glue
  File "mypy/typetraverser.py", line 52, in visit_callable_type
  File "mypy/types.py", line 625, in accept
  File "mypy/newsemanal/semanal_typeargs.py", line 47, in visit_instance__TypeVisitor_glue
  File "mypy/newsemanal/semanal_typeargs.py", line 51, in visit_instance
AttributeError: attribute 'defn' of 'TypeInfo' undefined
dataclassinit.py: : note: use --pdb to drop into pdb

And on master with:

$ mypy --new-semantic-analyzer dataclassinit.py 
dataclassinit.py: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.710+dev.aec4f2affc50664ce618acc2d74b34bd0961818d
Traceback (most recent call last):
  File "/home/jelle/repos/mypy/.venv/bin/mypy", line 11, in <module>
    load_entry_point('mypy', 'console_scripts', 'mypy')()
  File "/home/jelle/repos/mypy/mypy/__main__.py", line 7, in console_entry
    main(None)
  File "/home/jelle/repos/mypy/mypy/main.py", line 85, in main
    res = build.build(sources, options, None, flush_errors, fscache)
  File "/home/jelle/repos/mypy/mypy/build.py", line 163, in build
    result = _build(sources, options, alt_lib_path, flush_errors, fscache)
  File "/home/jelle/repos/mypy/mypy/build.py", line 219, in _build
    graph = dispatch(sources, manager)
  File "/home/jelle/repos/mypy/mypy/build.py", line 2462, in dispatch
    process_graph(graph, manager)
  File "/home/jelle/repos/mypy/mypy/build.py", line 2765, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/home/jelle/repos/mypy/mypy/build.py", line 2863, in process_stale_scc
    semantic_analysis_for_scc(graph, scc, manager.errors)
  File "/home/jelle/repos/mypy/mypy/newsemanal/semanal_main.py", line 79, in semantic_analysis_for_scc
    check_type_arguments(graph, scc, errors)
  File "/home/jelle/repos/mypy/mypy/newsemanal/semanal_main.py", line 307, in check_type_arguments
    state.tree.accept(analyzer)
  File "/home/jelle/ans/venv/lib/python3.6/contextlib.py", line 99, in __exit__
    self.gen.throw(type, value, traceback)
  File "/home/jelle/repos/mypy/mypy/build.py", line 1768, in wrap_context
    yield
  File "/home/jelle/repos/mypy/mypy/newsemanal/semanal_main.py", line 307, in check_type_arguments
    state.tree.accept(analyzer)
  File "/home/jelle/repos/mypy/mypy/nodes.py", line 275, in accept
    return visitor.visit_mypy_file(self)
  File "/home/jelle/repos/mypy/mypy/newsemanal/semanal_typeargs.py", line 33, in visit_mypy_file
    super().visit_mypy_file(o)
  File "/home/jelle/repos/mypy/mypy/traverser.py", line 33, in visit_mypy_file
    d.accept(self)
  File "/home/jelle/repos/mypy/mypy/nodes.py", line 901, in accept
    return visitor.visit_class_def(self)
  File "/home/jelle/repos/mypy/mypy/newsemanal/semanal_typeargs.py", line 44, in visit_class_def
    super().visit_class_def(defn)
  File "/home/jelle/repos/mypy/mypy/mixedtraverser.py", line 28, in visit_class_def
    super().visit_class_def(o)
  File "/home/jelle/repos/mypy/mypy/traverser.py", line 65, in visit_class_def
    o.defs.accept(self)
  File "/home/jelle/repos/mypy/mypy/nodes.py", line 966, in accept
    return visitor.visit_block(self)
  File "/home/jelle/repos/mypy/mypy/newsemanal/semanal_typeargs.py", line 48, in visit_block
    super().visit_block(o)
  File "/home/jelle/repos/mypy/mypy/traverser.py", line 37, in visit_block
    s.accept(self)
  File "/home/jelle/repos/mypy/mypy/nodes.py", line 643, in accept
    return visitor.visit_func_def(self)
  File "/home/jelle/repos/mypy/mypy/traverser.py", line 52, in visit_func_def
    self.visit_func(o)
  File "/home/jelle/repos/mypy/mypy/newsemanal/semanal_typeargs.py", line 40, in visit_func
    super().visit_func(defn)
  File "/home/jelle/repos/mypy/mypy/mixedtraverser.py", line 23, in visit_func
    self.visit_optional_type(o.type)
  File "/home/jelle/repos/mypy/mypy/mixedtraverser.py", line 91, in visit_optional_type
    t.accept(self)
  File "/home/jelle/repos/mypy/mypy/types.py", line 939, in accept
    return visitor.visit_callable_type(self)
  File "/home/jelle/repos/mypy/mypy/typetraverser.py", line 52, in visit_callable_type
    t.fallback.accept(self)
  File "/home/jelle/repos/mypy/mypy/types.py", line 630, in accept
    return visitor.visit_instance(self)
  File "/home/jelle/repos/mypy/mypy/newsemanal/semanal_typeargs.py", line 54, in visit_instance
    for (i, arg), tvar in zip(enumerate(t.args), info.defn.type_vars):
  File "/home/jelle/repos/mypy/mypy/nodes.py", line 2588, in __getattribute__
    raise AssertionError(object.__getattribute__(self, 'msg'))
AssertionError: fallback can't be filled out until semanal
dataclassinit.py: : note: use --pdb to drop into pdb
@JelleZijlstra JelleZijlstra added crash semantic-analyzer Problems that happen during semantic analysis labels May 6, 2019
@ilevkivskyi
Copy link
Member

This is essentially a duplicate of #6454. The cause is the duplicate definitions of __init__ (one user defined and one generated). The best fix for now is probably to just use the -redefinition hack (the first bullet point in Jukka's comment). Note that there is also another test case that crashes because of this [case testNewNamedTupleIllegalNames].

Maybe we can move this to the original issue and close this one? Or maybe vice-versa?

@JelleZijlstra
Copy link
Member Author

Thanks! Let's just close this and I'll leave a comment on the original issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash semantic-analyzer Problems that happen during semantic analysis
Projects
None yet
Development

No branches or pull requests

2 participants