graphql-python / graphql-python/graphene

Why SubclassWithMeta.__init_subclass__ terminates the super() chain?

オープン
#1,233 コメント 0 件 リアクション 1 件 担当者 0 名 GitHub で見る
✨ enhancement
主要言語
Python
スター
8.2k
フォーク
818
PR マージ指標
30日以内にマージされた PR はありません

説明

Is there a great reason why `graphene.utils.subclass_with_meta.SubclassWithMeta.__init_subclass__`, doesn't call `super().__init_subclass__()`?
https://github.com/graphql-python/graphene/blob/master/graphene/utils/subclass_with_meta.py#L21-#L46

The issue with this is IMO the following:

- Class `Foo` has defined a custom `__init_subclass__`.
- Class `Bar` derives from `Foo` and e.g. `graphene.types.ObjectType`.

Now if `Foo` is accidentally placed after `ObjectType` in `Bar`'s inheritance list, `Foo.__init_subclass__` will never be run.

Here's a quick demo:

```
from graphene.types import ObjectType

class Foo:
def __init_subclass__(cls):
print(f"Init Foo's subclass: {cls.__name__}")
super().__init_subclass__()

class Bar1(Foo, ObjectType):
pass

class Bar2(ObjectType, Foo):
pass
```

>Output:
>```
>Init Foo's subclass: Bar1
>```

[My proposed fix PR](https://github.com/graphql-python/graphene/pull/1234) would simply add `super().__init_subclass__()` to the last line of `SubclassWithMeta.__init_subclass__`.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

Start with graphene/utils/subclass_with_meta.py at lines 21-46 and reproduce the Foo, Bar1, and Bar2 example from the issue. Review the proposed fix in graphene/pull/1234 and verify that SubclassWithMeta.__init_subclass__ no longer stops the cooperative super() chain. Done means Foo.__init_subclass__ runs for both inheritance orders without breaking existing behavior.

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

評価

技術スタック
python
領域
backend
issue の種類
バグ
難易度
2/5
見積もり時間
1〜3時間
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
25/100

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

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