python / python/cpython

dataclass with slots=True, init=False raises AttributeError

Open
#98,247 8 comments 1 reaction 1 assignee View on GitHub

@ericvsmith is already working on this.

Since Oct 30, 2022.

stdlib topic-dataclasses type-bug
Dominant language
Python
Stars
77.2k
Forks
36k
PR merge metrics
PR metrics pending

Description

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'

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.