New submission from Raymond Hettinger <raymond.hettin...@gmail.com>:

The following code (simplified from a real example) triggers an unexpected 
TypeError:

    @dataclass
    class PrioritizedItem:
        priority: 'int'
        def __eq__(self, other):
            return self.priority == other.priority

This code gives the following trackback:

    Traceback (most recent call last):
      File "/Users/raymond/Documents/tmp16.py", line 16, in <module>
        @dataclass
      File 
"/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/dataclasses.py",
 line 598, in dataclass
        return wrap(_cls)
      File 
"/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/dataclasses.py",
 line 590, in wrap
        return _process_class(cls, repr, eq, order, hash, init, frozen)
      File 
"/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/dataclasses.py",
 line 539, in _process_class
        _set_attribute(cls, '__hash__', None)
      File 
"/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/dataclasses.py",
 line 444, in _set_attribute
        raise TypeError(f'Cannot overwrite attribute {name} '
    TypeError: Cannot overwrite attribute __hash__ in PrioritizedItem

----------
assignee: eric.smith
components: Library (Lib)
files: data_class_type_error.py
messages: 309901
nosy: eric.smith, rhettinger
priority: normal
severity: normal
status: open
title: Unusual TypeError with dataclass decorator
type: behavior
versions: Python 3.7
Added file: https://bugs.python.org/file47384/data_class_type_error.py

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue32546>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to