graphql-python / graphql-python/graphene

Why SubclassWithMeta.__init_subclass__ terminates the super() chain?

Đang mở
#1,233 0 bình luận 1 reaction 0 người được giao Xem trên GitHub
✨ enhancement
Ngôn ngữ chính
Python
Star
8.2k
Fork
818
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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__`.

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Hướng nghiên cứu

Bắt đầu với graphene/utils/subclass_with_meta.py tại các dòng 21-46 và tái hiện ví dụ Foo, Bar1 và Bar2 từ issue. Xem xét bản sửa được đề xuất trong graphene/pull/1234 và xác minh rằng SubclassWithMeta.__init_subclass__ không còn dừng chuỗi super() mang tính hợp tác. Được xem là hoàn tất khi Foo.__init_subclass__ chạy với cả hai thứ tự kế thừa mà không làm hỏng hành vi hiện có.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
backend
Loại issue
Lỗi
Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.