Skip to content

Internal error inheriting from dataclass with duplicate field #7792

@ghost

Description

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

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.
from dataclasses import dataclass


@dataclass
class A:
    x: int = 0
    x: int = 0


@dataclass
class B(A):
    pass
  • What is the actual behavior/output?
a.py:6: error: Name 'x' already defined on line 5
a.py:10: error: INTERNAL ERROR -- Please try using mypy master on Github:
https://mypy.rtfd.io/en/latest/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 0.750+dev.09c1fc7a4c19fe76c2ca9f0c58eaeccfe1ef9ed5
  • What is the behavior/output you expect?

a.py:6: error: Name 'x' already defined on line 5 and no internal error

  • What are the versions of mypy and Python you are using?
    Do you see the same issue after installing mypy from Git master?

My mypy --version is mypy 0.750+dev.09c1fc7a4c19fe76c2ca9f0c58eaeccfe1ef9ed5
python --version is Python 3.7.2

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

None

  • If mypy crashed with a traceback, please paste
    the full traceback below.
Traceback (most recent call last):
  File "C:\Users\anhans\AppData\Local\Programs\Python\Python37-32\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Users\anhans\AppData\Local\Programs\Python\Python37-32\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\anhans\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mypy\__main__.py", line 12, in <module>
    main(None, sys.stdout, sys.stderr)
  File "C:\Users\anhans\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mypy\main.py", line 88, in main
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
  File "C:\Users\anhans\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mypy\build.py", line 164, in build
    result = _build(sources, options, alt_lib_path, flush_errors, fscache, stdout, stderr)
  File "C:\Users\anhans\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mypy\build.py", line 230, in _build
    graph = dispatch(sources, manager, stdout)
  File "C:\Users\anhans\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mypy\build.py", line 2567, in dispatch
    process_graph(graph, manager)
  File "C:\Users\anhans\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mypy\build.py", line 2876, in process_graph
    process_stale_scc(graph, scc, manager)
  File "C:\Users\anhans\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mypy\build.py", line 2969, in process_stale_scc
    mypy.semanal_main.semantic_analysis_for_scc(graph, scc, manager.errors)
  File "C:\Users\anhans\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mypy\semanal_main.py", line 77, in semantic_analysis_for_scc
    process_top_levels(graph, scc, patches)
  File "C:\Users\anhans\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mypy\semanal_main.py", line 202, in process_top_levels
    patches)
  File "C:\Users\anhans\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mypy\semanal_main.py", line 330, in semantic_analyze_target
    active_type=active_type)
  File "C:\Users\anhans\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mypy\semanal.py", line 379, in refresh_partial
    self.refresh_top_level(node)
  File "C:\Users\anhans\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mypy\semanal.py", line 390, in refresh_top_level
    self.accept(d)
  File "C:\Users\anhans\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mypy\semanal.py", line 4631, in accept
    node.accept(self)
  File "C:\Users\anhans\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mypy\nodes.py", line 927, in accept
    return visitor.visit_class_def(self)
  File "C:\Users\anhans\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mypy\semanal.py", line 1023, in visit_class_def
    self.analyze_class(defn)
  File "C:\Users\anhans\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mypy\semanal.py", line 1094, in analyze_class
    self.analyze_class_body_common(defn)
  File "C:\Users\anhans\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mypy\semanal.py", line 1103, in analyze_class_body_common
    self.apply_class_plugin_hooks(defn)
  File "C:\Users\anhans\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mypy\semanal.py", line 1149, in apply_class_plugin_hooks
    hook(ClassDefContext(defn, decorator, self))
  File "C:\Users\anhans\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mypy\plugins\dataclasses.py", line 367, in dataclass_class_maker_callback
    transformer.transform()
  File "C:\Users\anhans\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mypy\plugins\dataclasses.py", line 79, in transform
    attributes = self.collect_attributes()
  File "C:\Users\anhans\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mypy\plugins\dataclasses.py", line 318, in collect_attributes
    (attr,) = [a for a in all_attrs if a.name == name]
ValueError: not enough values to unpack (expected 1, got 0)
a.py:10: : note: use --pdb to drop into pdb

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions