[New-bugs-announce] [issue32546] Unusual TypeError with dataclass decorator

Raymond Hettinger report at bugs.python.org
Sat Jan 13 16:26:23 EST 2018


New submission from Raymond Hettinger <raymond.hettinger at 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 <report at bugs.python.org>
<https://bugs.python.org/issue32546>
_______________________________________


More information about the New-bugs-announce mailing list