Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

The subclass of `dict` is not respected on `>=2024.11.0`

オープン
#8,932 コメント 2 件 リアクション 2 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
python

調査の方向性

提供された Client.submit と as_completed の例で問題を再現し、その後、dask.distributed が使用する送信およびシリアライズの経路を調査します。TestDict サブクラスが Dask 2024.11.0 で変更されずに test_subclass に到達し、例が属性値を正常に出力できれば完了です。

索引モデルが issue の本文から書いたものです。

説明

bug

Describe the issue:
The subclass is not respected. I noticed the issue on subclass of dict, not sure if it's more general. See below for details.

Minimal Complete Verifiable Example:

from dask.distributed import Client, as_completed

class TestDict(dict):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    def __getattr__(self, key: str):
        """ Allow access to items as attributes. """
        v = self.get(key, self)
        if v is self:
            raise AttributeError("has no attribute '{}'".format(key))
        return v

    def __repr__(self) -> str:
        return "(TestDict{})".format(super().__repr__())


def test_subclass(test_dict):
    print(f'input type {type(test_dict)}')
    print(f'get val {test_dict.a}')
    return 0


def main():
    client = Client()
    test_dict = TestDict(a=1)
    futures = [client.submit(test_subclass, test_dict)]
    for f in as_completed(futures):
        res = f.result()
        print(f"result {res}")


if __name__ == "__main__":
    main()

Anything else we need to know?:

The test code works as expected on <2024.11.0, which outputs

input type <class '__main__.TestDict'>
get val 1
result 0

on >=2024.11.0 outputs

input type <class 'dict'>
2024-11-13 05:01:36,954 - distributed.worker - ERROR - Compute Failed
Key:       test_subclass-e8dd185fef44ec112f057d9b352f913f
State:     executing
Task:  <Task 'test_subclass-e8dd185fef44ec112f057d9b352f913f' test_subclass(...)>
Exception: 'AttributeError("\'dict\' object has no attribute \'a\'")'
Traceback: '  File "/home/ubuntu/data/home/ubuntu/test_dask.py", line 20, in test_subclass\n    print(f\'get val {test_dict.a}\')\n'

Traceback (most recent call last):
  File "/home/ubuntu/data/home/ubuntu/test_dask.py", line 34, in <module>
    main()
  File "/home/ubuntu/data/home/ubuntu/test_dask.py", line 29, in main
    res = f.result()
  File "/home/ubuntu/.local/lib/python3.10/site-packages/distributed/client.py", line 402, in result
    return self.client.sync(self._result, callback_timeout=timeout)
  File "/home/ubuntu/data/home/ubuntu/test_dask.py", line 20, in test_subclass
    print(f'get val {test_dict.a}')

Environment:

  • Dask version: 2024.11.0
  • Python version: 3.10
  • Operating System: ubuntu 22.04
  • Install method (conda, pip, source): pip
主要言語
Python
スター
1.7k
フォーク
778
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

dask/distributed のほかの issue

dask/distributed の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。