Removed AbstractType

This commit is contained in:
Syrus Akbary 2017-07-11 21:23:39 -07:00
parent 2d557d6ed7
commit f0edcb224a
6 changed files with 11 additions and 65 deletions

View File

@ -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)

View File

@ -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')

View File

@ -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(),
}

View File

@ -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):

View File

@ -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):

View File

@ -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