Repository: polygraph-python/polygraph

Issue:
PolygraphType: Rename `_type` to `__type`

Comments:

Patch:
diff --git a/polygraph/types/basic_type.py b/polygraph/types/basic_type.py
index 900110a..3498d26 100644
--- a/polygraph/types/basic_type.py
+++ b/polygraph/types/basic_type.py
@@ -3,6 +3,10 @@ from polygraph.types.definitions import TypeDefinition, TypeKind
 from polygraph.utils.trim_docstring import trim_docstring
 
 
+def typedef(type_):
+    return type_.__type
+
+
 class PolygraphTypeMeta(type):
     def __new__(cls, name, bases, namespace):
         default_description = trim_docstring(namespace.get("__doc__", ""))
@@ -17,7 +21,7 @@ class PolygraphTypeMeta(type):
                 meta = None
 
         if meta:
-            namespace["_type"] = TypeDefinition(
+            namespace["__type"] = TypeDefinition(
                 kind=getattr(meta, "kind"),
                 name=getattr(meta, "name", name) or name,
                 description=getattr(meta, "description", default_description),
@@ -32,7 +36,7 @@ class PolygraphTypeMeta(type):
         return super(PolygraphTypeMeta, cls).__new__(cls, name, bases, namespace)
 
     def __str__(self):
-        return str(self._type.name)
+        return str(typedef(self).name)
 
     def __or__(self, other):
         """
@@ -99,7 +103,7 @@ class Union(PolygraphOutputType, PolygraphType):
             message = "All types must be subclasses of PolygraphType. Invalid values: "\
                       "{}".format(", ".join(bad_types))
             raise PolygraphSchemaError(message)
-        type_names = [t._type.name for t in types]
+        type_names = [typedef(t).name for t in types]
 
         def __new_from_value__(cls, value):
             if not any(isinstance(value, t) for t in types):
@@ -132,7 +136,7 @@ class List(PolygraphType):
     """
 
     def __new__(cls, type_):
-        type_name = type_._type.name
+        type_name = typedef(type_).name
 
         def __new_from_value__(cls, value):
             if value is None:
@@ -157,7 +161,7 @@ class NonNull(PolygraphType):
     Represents a type for which null is not a valid result.
     """
     def __new__(cls, type_):
-        type_name = type_._type.name
+        type_name = typedef(type_).name
 
         if issubclass(type, NonNull):
             raise TypeError("NonNull cannot modify NonNull types")


Test patch:
diff --git a/polygraph/types/tests/test_scalars.py b/polygraph/types/tests/test_scalars.py
index 79ccae2..8eecd6a 100644
--- a/polygraph/types/tests/test_scalars.py
+++ b/polygraph/types/tests/test_scalars.py
@@ -1,5 +1,6 @@
 from unittest import TestCase
 
+from polygraph.types.basic_type import typedef
 from polygraph.types.scalar import ID, Boolean, Float, Int, String
 
 
@@ -43,7 +44,7 @@ class BooleanTest(TestCase):
     def test_class_types(self):
         self.assertTrue(Boolean(True))
         self.assertFalse(Boolean(False))
-        self.assertEqual(Boolean._type.name, "Boolean")
+        self.assertEqual(typedef(Boolean).name, "Boolean")
 
     def test_none(self):
         self.assertIsNone(Boolean(None))
diff --git a/polygraph/types/tests/test_types.py b/polygraph/types/tests/test_types.py
index 6dc1e57..aa4bd3a 100644
--- a/polygraph/types/tests/test_types.py
+++ b/polygraph/types/tests/test_types.py
@@ -1,19 +1,19 @@
 from unittest import TestCase, skip
 
 from polygraph.exceptions import PolygraphValueError
-from polygraph.types.basic_type import List, NonNull
+from polygraph.types.basic_type import List, NonNull, typedef
 from polygraph.types.scalar import Boolean, Int, String
 from polygraph.utils.trim_docstring import trim_docstring
 
 
 class TypeMetaTest(TestCase):
     def test_scalar_meta(self):
-        self.assertEqual(Int._type.name, "Int")
-        self.assertEqual(Int._type.description, trim_docstring(Int.__doc__))
-        self.assertEqual(String._type.name, "String")
-        self.assertEqual(String._type.description, trim_docstring(String.__doc__))
-        self.assertEqual(Boolean._type.name, "Boolean")
-        self.assertEqual(Boolean._type.description, trim_docstring(Boolean.__doc__))
+        self.assertEqual(typedef(Int).name, "Int")
+        self.assertEqual(typedef(Int).description, trim_docstring(Int.__doc__))
+        self.assertEqual(typedef(String).name, "String")
+        self.assertEqual(typedef(String).description, trim_docstring(String.__doc__))
+        self.assertEqual(typedef(Boolean).name, "Boolean")
+        self.assertEqual(typedef(Boolean).description, trim_docstring(Boolean.__doc__))
 
     def test_type_string(self):
         self.assertEqual(str(Int), "Int")
@@ -26,8 +26,8 @@ class TypeMetaTest(TestCase):
             """Not the description"""
             pass
 
-        self.assertEqual(FancyString._type.name, "String")
-        self.assertNotEqual(FancyString._type.description, "Not the description")
+        self.assertEqual(FancyString.__type.name, "String")
+        self.assertNotEqual(FancyString.__type.description, "Not the description")
 
 
 class NonNullTest(TestCase):