From a3b215d8911a6b24e0db5a0b2cbd8468e7512d0c Mon Sep 17 00:00:00 2001 From: Jonathan Kim Date: Fri, 27 Sep 2019 09:54:19 +0100 Subject: [PATCH] Remove AbstractType (#1053) --- docs/types/abstracttypes.rst | 43 ----------------------- docs/types/index.rst | 1 - graphene/__init__.py | 3 -- graphene/types/__init__.py | 5 --- graphene/types/abstracttype.py | 11 ------ graphene/types/tests/test_abstracttype.py | 39 -------------------- 6 files changed, 102 deletions(-) delete mode 100644 docs/types/abstracttypes.rst delete mode 100644 graphene/types/abstracttype.py delete mode 100644 graphene/types/tests/test_abstracttype.py diff --git a/docs/types/abstracttypes.rst b/docs/types/abstracttypes.rst deleted file mode 100644 index 093cfd93..00000000 --- a/docs/types/abstracttypes.rst +++ /dev/null @@ -1,43 +0,0 @@ -AbstractTypes -============= - -An AbstractType contains fields that can be shared among -``graphene.ObjectType``, ``graphene.Interface``, -``graphene.InputObjectType`` or other ``graphene.AbstractType``. - -The basics: - -- Each AbstractType is a Python class that inherits from ``graphene.AbstractType``. -- Each attribute of the AbstractType represents a field (a ``graphene.Field`` or - ``graphene.InputField`` depending on where it is mounted) - -Quick example -------------- - -In this example UserFields is an ``AbstractType`` with a name. ``User`` and -``UserInput`` are two types that have their own fields -plus the ones defined in ``UserFields``. - -.. code:: python - - import graphene - - class UserFields(graphene.AbstractType): - name = graphene.String() - - class User(graphene.ObjectType, UserFields): - pass - - class UserInput(graphene.InputObjectType, UserFields): - pass - - -.. code:: - - type User { - name: String - } - - inputtype UserInput { - name: String - } diff --git a/docs/types/index.rst b/docs/types/index.rst index d44894af..d82beb33 100644 --- a/docs/types/index.rst +++ b/docs/types/index.rst @@ -15,4 +15,3 @@ Types Reference interfaces unions mutations - abstracttypes diff --git a/graphene/__init__.py b/graphene/__init__.py index d7d7ef88..f667e014 100644 --- a/graphene/__init__.py +++ b/graphene/__init__.py @@ -1,7 +1,6 @@ from .pyutils.version import get_version from .types import ( - AbstractType, ObjectType, InputObjectType, Interface, @@ -86,6 +85,4 @@ __all__ = [ "lazy_import", "Context", "ResolveInfo", - # Deprecated - "AbstractType", ] diff --git a/graphene/types/__init__.py b/graphene/types/__init__.py index 292db235..680149a3 100644 --- a/graphene/types/__init__.py +++ b/graphene/types/__init__.py @@ -20,9 +20,6 @@ from .dynamic import Dynamic from .union import Union from .context import Context -# Deprecated -from .abstracttype import AbstractType - __all__ = [ "ObjectType", @@ -52,6 +49,4 @@ __all__ = [ "Union", "Context", "ResolveInfo", - # Deprecated - "AbstractType", ] diff --git a/graphene/types/abstracttype.py b/graphene/types/abstracttype.py deleted file mode 100644 index 4eeb7f9c..00000000 --- a/graphene/types/abstracttype.py +++ /dev/null @@ -1,11 +0,0 @@ -from ..utils.deprecated import warn_deprecation -from ..utils.subclass_with_meta import SubclassWithMeta - - -class AbstractType(SubclassWithMeta): - def __init_subclass__(cls, *args, **kwargs): - warn_deprecation( - "Abstract type is deprecated, please use normal object inheritance instead.\n" - "See more: https://github.com/graphql-python/graphene/blob/master/UPGRADE-v2.0.md#deprecations" - ) - 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 a50c8757..00000000 --- a/graphene/types/tests/test_abstracttype.py +++ /dev/null @@ -1,39 +0,0 @@ -from pytest import deprecated_call - -from ..abstracttype import AbstractType -from ..field import Field -from ..objecttype import ObjectType -from ..unmountedtype import UnmountedType - - -class MyType(ObjectType): - pass - - -class MyScalar(UnmountedType): - def get_type(self): - return MyType - - -def test_abstract_objecttype_warn_deprecation(): - with deprecated_call(): - - # noinspection PyUnusedLocal - class MyAbstractType(AbstractType): - field1 = MyScalar() - - -def test_generate_objecttype_inherit_abstracttype(): - with deprecated_call(): - - class MyAbstractType(AbstractType): - field1 = MyScalar() - - class MyObjectType(ObjectType, MyAbstractType): - field2 = MyScalar() - - assert MyObjectType._meta.description is None - assert MyObjectType._meta.interfaces == () - assert MyObjectType._meta.name == "MyObjectType" - assert list(MyObjectType._meta.fields) == ["field1", "field2"] - assert list(map(type, MyObjectType._meta.fields.values())) == [Field, Field]