[New-bugs-announce] [issue44649] dataclasses slots with init=False field raises AttributeException

Christodoulos Tsoulloftas report at bugs.python.org
Thu Jul 15 15:06:03 EDT 2021


New submission from Christodoulos Tsoulloftas <chris at komposta.net>:

I am trying the new slots directive but I get an AttributeError when I try to access a field with init=False


>>> from dataclasses import dataclass, field
>>> 
>>> @dataclass(slots=True)
... class Example:
...     a: str
...     b: str = field(default="b", init=False)
... 
>>> obj = Example("a")
>>> obj.__slots__
('a', 'b')
>>> obj.
obj.a  obj.b  
>>> obj.a
'a'
>>> obj.b
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: b. Did you mean: 'b'?
>>> 



❯ python --version
Python 3.10.0b4+

----------
components: Library (Lib)
messages: 397575
nosy: tefra
priority: normal
severity: normal
status: open
title: dataclasses slots with init=False field raises AttributeException
type: behavior
versions: Python 3.10

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44649>
_______________________________________


More information about the New-bugs-announce mailing list