diff --git a/graphene/types/abstracttype.py b/graphene/types/abstracttype.py index dcfd7a20..0fe75a44 100644 --- a/graphene/types/abstracttype.py +++ b/graphene/types/abstracttype.py @@ -1,8 +1,8 @@ -class AbstractTypeMeta(type): - pass - +from ..pyutils.init_subclass import InitSubclassMeta class AbstractType(object): + __metaclass__ = InitSubclassMeta + def __init_subclass__(cls, *args, **kwargs): print("Abstract type is deprecated") super(AbstractType, cls).__init_subclass__(*args, **kwargs) diff --git a/graphene/types/tests/test_abstracttype.py b/graphene/types/tests/test_abstracttype.py deleted file mode 100644 index dabf1e68..00000000 --- a/graphene/types/tests/test_abstracttype.py +++ /dev/null @@ -1,42 +0,0 @@ - -from ..abstracttype import AbstractType -from ..field import Field -from ..unmountedtype import UnmountedType - - -class MyType(object): - pass - - -class MyScalar(UnmountedType): - - def get_type(self): - return MyType - - -def test_generate_abstracttype_with_fields(): - class MyAbstractType(AbstractType): - field = Field(MyType) - - assert 'field' in MyAbstractType._meta.fields - assert isinstance(MyAbstractType._meta.fields['field'], Field) - - -def test_generate_abstracttype_with_unmountedfields(): - class MyAbstractType(AbstractType): - field = UnmountedType(MyType) - - assert 'field' in MyAbstractType._meta.fields - assert isinstance(MyAbstractType._meta.fields['field'], UnmountedType) - - -def test_generate_abstracttype_inheritance(): - class MyAbstractType1(AbstractType): - field1 = UnmountedType(MyType) - - class MyAbstractType2(MyAbstractType1): - field2 = UnmountedType(MyType) - - assert list(MyAbstractType2._meta.fields.keys()) == ['field1', 'field2'] - assert not hasattr(MyAbstractType1, 'field1') - assert not hasattr(MyAbstractType2, 'field2') diff --git a/graphene/types/tests/test_definition.py b/graphene/types/tests/test_definition.py index b040c42d..af9168c9 100644 --- a/graphene/types/tests/test_definition.py +++ b/graphene/types/tests/test_definition.py @@ -1,6 +1,5 @@ -from ..abstracttype import AbstractType from ..argument import Argument from ..enum import Enum from ..field import Field @@ -296,7 +295,7 @@ def test_stringifies_simple_types(): def test_does_not_mutate_passed_field_definitions(): - class CommonFields(AbstractType): + class CommonFields(object): field1 = String() field2 = String(id=String()) @@ -307,12 +306,8 @@ def test_does_not_mutate_passed_field_definitions(): pass assert TestObject1._meta.fields == TestObject2._meta.fields - assert CommonFields._meta.fields == { - 'field1': String(), - 'field2': String(id=String()), - } - class CommonFields(AbstractType): + class CommonFields(object): field1 = String() field2 = String() @@ -323,8 +318,3 @@ def test_does_not_mutate_passed_field_definitions(): pass assert TestInputObject1._meta.fields == TestInputObject2._meta.fields - - assert CommonFields._meta.fields == { - 'field1': String(), - 'field2': String(), - } diff --git a/graphene/types/tests/test_inputobjecttype.py b/graphene/types/tests/test_inputobjecttype.py index 7f8eaa7a..7cd3064c 100644 --- a/graphene/types/tests/test_inputobjecttype.py +++ b/graphene/types/tests/test_inputobjecttype.py @@ -1,5 +1,4 @@ -from ..abstracttype import AbstractType from ..field import Field from ..argument import Argument from ..inputfield import InputField @@ -80,7 +79,7 @@ def test_generate_inputobjecttype_as_argument(): def test_generate_inputobjecttype_inherit_abstracttype(): - class MyAbstractType(AbstractType): + class MyAbstractType(object): field1 = MyScalar(MyType) class MyInputObjectType(InputObjectType, MyAbstractType): @@ -91,7 +90,7 @@ def test_generate_inputobjecttype_inherit_abstracttype(): def test_generate_inputobjecttype_inherit_abstracttype_reversed(): - class MyAbstractType(AbstractType): + class MyAbstractType(object): field1 = MyScalar(MyType) class MyInputObjectType(MyAbstractType, InputObjectType): diff --git a/graphene/types/tests/test_objecttype.py b/graphene/types/tests/test_objecttype.py index 8a1cf898..2304d7b6 100644 --- a/graphene/types/tests/test_objecttype.py +++ b/graphene/types/tests/test_objecttype.py @@ -1,6 +1,5 @@ import pytest -from ..abstracttype import AbstractType from ..field import Field from ..interface import Interface from ..objecttype import ObjectType @@ -89,7 +88,7 @@ def test_ordered_fields_in_objecttype(): def test_generate_objecttype_inherit_abstracttype(): - class MyAbstractType(AbstractType): + class MyAbstractType(object): field1 = MyScalar() class MyObjectType(ObjectType, MyAbstractType): @@ -103,7 +102,7 @@ def test_generate_objecttype_inherit_abstracttype(): def test_generate_objecttype_inherit_abstracttype_reversed(): - class MyAbstractType(AbstractType): + class MyAbstractType(object): field1 = MyScalar() class MyObjectType(MyAbstractType, ObjectType): diff --git a/graphene/types/utils.py b/graphene/types/utils.py index 7c59bbaf..598b7f1f 100644 --- a/graphene/types/utils.py +++ b/graphene/types/utils.py @@ -23,9 +23,9 @@ def get_base_fields(bases, _as=None): Get all the fields in the given bases ''' fields = OrderedDict() - from ..types import AbstractType, Interface + from ..types import Interface # We allow inheritance in AbstractTypes and Interfaces but not ObjectTypes - inherited_bases = (AbstractType, Interface) + inherited_bases = (Interface) for base in bases: if base in inherited_bases or not issubclass(base, inherited_bases): continue