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
This commit is contained in:
Eran Kampf 2019-05-31 14:31:17 -07:00 committed by GitHub
parent 1fcdeaac65
commit eb7966eca7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 2 deletions

View File

@ -34,7 +34,9 @@ class BaseType(SubclassWithMeta):
return type(class_name, (cls,), {"Meta": options}) return type(class_name, (cls,), {"Meta": options})
@classmethod @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" assert "_meta" not in cls.__dict__, "Can't assign directly meta"
if not _meta: if not _meta:
return return

View File

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

View File

@ -10,7 +10,8 @@ setenv =
PYTHONPATH = .:{envdir} PYTHONPATH = .:{envdir}
commands = commands =
py{27,py}: py.test --cov=graphene graphene examples {posargs} 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] [testenv:pre-commit]
basepython=python3.6 basepython=python3.6