graphql-python / graphql-python/graphene

Why SubclassWithMeta.__init_subclass__ terminates the super() chain?

Aperta
#1,233 0 commenti 1 reazione 0 assegnatari Vedi su GitHub
✨ enhancement
Lingua principale
Python
Stelle
8.2k
Fork
818
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.