mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-26 11:33:55 +03:00
Make init_subclass work in Python 3.5
This commit is contained in:
parent
e38007868e
commit
563ca23d00
|
@ -1,19 +1,19 @@
|
|||
import six
|
||||
is_init_subclass_available = hasattr(object, '__init_subclass__')
|
||||
|
||||
if six.PY2:
|
||||
if not is_init_subclass_available:
|
||||
class InitSubclassMeta(type):
|
||||
"""Metaclass that implements PEP 487 protocol"""
|
||||
def __new__(cls, name, bases, ns):
|
||||
def __new__(cls, name, bases, ns, **kwargs):
|
||||
__init_subclass__ = ns.pop('__init_subclass__', None)
|
||||
if __init_subclass__:
|
||||
__init_subclass__ = classmethod(__init_subclass__)
|
||||
ns['__init_subclass__'] = __init_subclass__
|
||||
return super(InitSubclassMeta, cls).__new__(cls, name, bases, ns)
|
||||
return super(InitSubclassMeta, cls).__new__(cls, name, bases, ns, **kwargs)
|
||||
|
||||
def __init__(cls, name, bases, ns):
|
||||
def __init__(cls, name, bases, ns, **kwargs):
|
||||
super(InitSubclassMeta, cls).__init__(name, bases, ns)
|
||||
super_class = super(cls, cls)
|
||||
if hasattr(super_class, '__init_subclass__'):
|
||||
super_class.__init_subclass__.__func__(cls)
|
||||
super_class.__init_subclass__.__func__(cls, **kwargs)
|
||||
else:
|
||||
InitSubclassMeta = type
|
||||
|
|
Loading…
Reference in New Issue
Block a user