Skip to content

dataclass with slots=True, init=False raises AttributeError #98247

@noskill

Description

@noskill

Python 3.10.4
dataclass with slots=True, init=False raises AttributeError on attribute access

from dataclasses import dataclass

@dataclass(slots=True, init=False)
class WorldState:
    is_mission_running: bool = False

w = WorldState()
w.is_mission_running

Traceback (most recent call last):
File "", line 1, in
AttributeError: 'WorldState' object has no attribute 'is_mission_running'

Metadata

Metadata

Assignees

Labels

stdlibStandard Library Python modules in the Lib/ directorytopic-dataclassestype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions