From eb7966eca7f9f90da1ac60c97aafa542ae3d0b38 Mon Sep 17 00:00:00 2001 From: Eran Kampf <205185+ekampf@users.noreply.github.com> Date: Fri, 31 May 2019 14:31:17 -0700 Subject: [PATCH] Fix for metaclasses that use type annotation (Issue #979) (#981) * Replicate error with test * Fix - ignore parameters we do not recognize * Seperate Python3.6+ tests to their own folder * lint * Unused import * Black formatting --- graphene/types/base.py | 4 +++- tests_py36/test_objecttype.py | 15 +++++++++++++++ tox.ini | 3 ++- 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 tests_py36/test_objecttype.py diff --git a/graphene/types/base.py b/graphene/types/base.py index 75685d98..f43feb47 100644 --- a/graphene/types/base.py +++ b/graphene/types/base.py @@ -34,7 +34,9 @@ class BaseType(SubclassWithMeta): return type(class_name, (cls,), {"Meta": options}) @classmethod - def __init_subclass_with_meta__(cls, name=None, description=None, _meta=None): + def __init_subclass_with_meta__( + cls, name=None, description=None, _meta=None, **_kwargs + ): assert "_meta" not in cls.__dict__, "Can't assign directly meta" if not _meta: return diff --git a/tests_py36/test_objecttype.py b/tests_py36/test_objecttype.py new file mode 100644 index 00000000..bce38d94 --- /dev/null +++ b/tests_py36/test_objecttype.py @@ -0,0 +1,15 @@ +from graphene import Schema, ObjectType, String + + +def test_objecttype_meta_with_annotations(): + class Query(ObjectType): + class Meta: + name: str = "oops" + + hello = String() + + def resolve_hello(self, info): + return "Hello" + + schema = Schema(query=Query) + assert schema is not None diff --git a/tox.ini b/tox.ini index c1dbd01d..57d1f78e 100644 --- a/tox.ini +++ b/tox.ini @@ -10,7 +10,8 @@ setenv = PYTHONPATH = .:{envdir} commands = py{27,py}: py.test --cov=graphene graphene examples {posargs} - py{35,36,37}: py.test --cov=graphene graphene examples tests_asyncio {posargs} + py{35}: py.test --cov=graphene graphene examples tests_asyncio {posargs} + py{36,37}: py.test --cov=graphene graphene examples tests_asyncio tests_py36 {posargs} [testenv:pre-commit] basepython=python3.6