From c7c611266b155c1ee46261744be98d8c084b20f0 Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Wed, 26 Jul 2017 19:26:54 -0700 Subject: [PATCH] Allow types to be abstract --- graphene/types/interface.py | 4 +--- graphene/types/mutation.py | 4 +--- graphene/types/objecttype.py | 4 +--- graphene/utils/subclass_with_meta.py | 14 +++++++++++--- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/graphene/types/interface.py b/graphene/types/interface.py index 389cb82c..054b7229 100644 --- a/graphene/types/interface.py +++ b/graphene/types/interface.py @@ -19,9 +19,7 @@ class Interface(BaseType): when the field is resolved. ''' @classmethod - def __init_subclass_with_meta__(cls, abstract=False, _meta=None, **options): - if abstract: - return + def __init_subclass_with_meta__(cls, _meta=None, **options): if not _meta: _meta = InterfaceOptions(cls) diff --git a/graphene/types/mutation.py b/graphene/types/mutation.py index 431c1d87..32194e9e 100644 --- a/graphene/types/mutation.py +++ b/graphene/types/mutation.py @@ -20,9 +20,7 @@ class Mutation(ObjectType): ''' @classmethod def __init_subclass_with_meta__(cls, resolver=None, output=None, arguments=None, - _meta=None, abstract=False, **options): - if abstract: - return + _meta=None, **options): if not _meta: _meta = MutationOptions(cls) diff --git a/graphene/types/objecttype.py b/graphene/types/objecttype.py index 9987e4e4..c579a88e 100644 --- a/graphene/types/objecttype.py +++ b/graphene/types/objecttype.py @@ -22,9 +22,7 @@ class ObjectType(BaseType): def __init_subclass_with_meta__( cls, interfaces=(), possible_types=(), - default_resolver=None, _meta=None, abstract=False, **options): - if abstract: - return + default_resolver=None, _meta=None, **options): if not _meta: _meta = ObjectTypeOptions(cls) diff --git a/graphene/utils/subclass_with_meta.py b/graphene/utils/subclass_with_meta.py index f1ebfce9..9226e418 100644 --- a/graphene/utils/subclass_with_meta.py +++ b/graphene/utils/subclass_with_meta.py @@ -27,9 +27,17 @@ class SubclassWithMeta(six.with_metaclass(SubclassWithMeta_Meta)): raise Exception("Meta have to be either a class or a dict. Received {}".format(_Meta)) delattr(cls, "Meta") options = dict(meta_options, **_meta_props) - super_class = super(cls, cls) - if hasattr(super_class, '__init_subclass_with_meta__'): - super_class.__init_subclass_with_meta__(**options) + + abstract = options.pop('abstract', False) + if abstract: + assert not options, ( + "Abstract types can only contain the abstract attribute. " + "Received: abstract, {option_keys}" + ).format(option_keys=', '.join(options.keys())) + else: + super_class = super(cls, cls) + if hasattr(super_class, '__init_subclass_with_meta__'): + super_class.__init_subclass_with_meta__(**options) @classmethod def __init_subclass_with_meta__(cls, **meta_options):