Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Mixed inheritance between slotted and non slotted classes leads to issues with parallelisation.

未关闭
#1,020 14 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

@saadkhantareen 已经在做这个了。

开始于 2026年10月15日。

  • #1643 来自 @saadkhantareen —— 未关闭

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
python
领域
backend

调研方向

Start with the provided mixed-inheritance reproducer and inspect how the Child instance is copied for multiprocessing, particularly the interaction between dict and slots. The work is done when the copied object retains z and name and the pool example succeeds, with regression coverage for the failing case.

由索引模型根据 Issue 内容生成。

描述

Documentation Thinking

Mixed inheritance between slotted and non-slotted classes seems to lead to some issues when object are copied for parallelization.

The following code example does not work and raises: AttributeError: 'Child' object has no attribute 'z'

import attrs
import multiprocessing as mp

@attrs.define(slots=False, kw_only=True)
class Parent:
    name: str 
    
@attrs.define
class Child(Parent):
    x: float
    
    def __attrs_post_init__(self):
        self.z = self.x + 2

    def arg_plus_z(self, arg):
        return self.z + arg

test = Child(3, name = "as")

with mp.Pool(processes=4) as pool:
    result = pool.map(test.arg_plus_z, range(100))

whilst adding slots=False to the child class or registering z using z: float = attrs.field(default = None, init=False) does work:

import attrs
import multiprocessing as mp

@attrs.define(slots=False, kw_only=True)
class Parent:
    name: str 
    
@attrs.define(slots=False)
class Child(Parent):
    x: float
    
    def __attrs_post_init__(self):
        self.z = self.x + 2

    def arg_plus_z(self, arg):
        return self.z + arg

test = Child(3, name = "as")

with mp.Pool(processes=4) as pool:
    result = pool.map(test.arg_plus_z, range(100))

It seems like the object copy of test passed to each one of the processes does not copy the __dict__ (which includes z and name) but only the __slots__.

I know that according to the attrs documentation mixed inheritance between slotted and non slotted classes is considered a bad practice. I stumbled across this by accident and it might also be more of a missing feature than a bug.

Meta:

  • attrs-version: '21.4.0'
  • python-version: '3.9.13'
主要语言
Python
星标
5.9k
派生
503
平均合并
4 天 18 小时
30 天内合并 PR
5

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

python-attrs/attrs 的其他 Issue

查看 python-attrs/attrs 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。