Added mypy static checking

This commit is contained in:
Syrus Akbary 2017-08-07 20:48:20 -07:00
parent 19bf9b3713
commit 7cfec55410
10 changed files with 63 additions and 5 deletions

1
.gitignore vendored
View File

@ -80,3 +80,4 @@ target/
# Databases
*.sqlite3
.vscode
.mypy_cache

View File

@ -27,12 +27,19 @@ install:
elif [ "$TEST_TYPE" = lint ]; then
pip install flake8
fi
elif [ "$TEST_TYPE" = mypy ]; then
pip install mypy
fi
script:
- |
if [ "$TEST_TYPE" = lint ]; then
echo "Checking Python code lint."
flake8 graphene
exit
elif [ "$TEST_TYPE" = mypy ]; then
echo "Checking Python types."
mypy graphene
exit
elif [ "$TEST_TYPE" = build ]; then
py.test --cov=graphene graphene examples
fi
@ -51,6 +58,8 @@ matrix:
include:
- python: '2.7'
env: TEST_TYPE=lint
- python: '3.6'
env: TEST_TYPE=mypy
deploy:
provider: pypi
user: syrusakbary

View File

@ -16,4 +16,4 @@ if not is_init_subclass_available:
if hasattr(super_class, '__init_subclass__'):
super_class.__init_subclass__.__func__(cls, **kwargs)
else:
InitSubclassMeta = type
InitSubclassMeta = type # type: ignore

View File

@ -6,8 +6,14 @@ from .unmountedtype import UnmountedType
from .utils import yank_fields_from_attrs
# For static type checking with Mypy
MYPY = False
if MYPY:
from typing import Dict, Callable
class InputObjectTypeOptions(BaseOptions):
fields = None # type: Dict[str, Field]
fields = None # type: Dict[str, InputField]
create_container = None # type: Callable

View File

@ -4,6 +4,11 @@ from .base import BaseOptions, BaseType
from .field import Field
from .utils import yank_fields_from_attrs
# For static type checking with Mypy
MYPY = False
if MYPY:
from typing import Dict
class InterfaceOptions(BaseOptions):
fields = None # type: Dict[str, Field]

View File

@ -8,10 +8,17 @@ from .utils import yank_fields_from_attrs
from ..utils.deprecated import warn_deprecation
# For static type checking with Mypy
MYPY = False
if MYPY:
from .argument import Argument
from typing import Dict, Type, Callable
class MutationOptions(ObjectTypeOptions):
arguments = None # type: Dict[str, Argument]
output = None # type: Type[ObjectType]
resolver = None # type: Function
resolver = None # type: Callable
class Mutation(ObjectType):

View File

@ -5,10 +5,15 @@ from .field import Field
from .interface import Interface
from .utils import yank_fields_from_attrs
# For static type checking with Mypy
MYPY = False
if MYPY:
from typing import Dict, Iterable, Type
class ObjectTypeOptions(BaseOptions):
fields = None # type: Dict[str, Field]
interfaces = () # type: List[Type[Interface]]
interfaces = () # type: Iterable[Type[Interface]]
class ObjectType(BaseType):

View File

@ -86,6 +86,7 @@ class Float(Scalar):
@staticmethod
def coerce_float(value):
# type: (Any) -> float
try:
return float(value)
except ValueError:

View File

@ -2,8 +2,15 @@ from .base import BaseOptions, BaseType
from .unmountedtype import UnmountedType
# For static type checking with Mypy
MYPY = False
if MYPY:
from .objecttype import ObjectType
from typing import Iterable, Type
class UnionOptions(BaseOptions):
types = () # type: List[Type[ObjectType]]
types = () # type: Iterable[Type[ObjectType]]
class Union(UnmountedType, BaseType):

17
mypy.ini Normal file
View File

@ -0,0 +1,17 @@
[mypy]
ignore_missing_imports = True
[mypy-graphene.pyutils.*]
ignore_errors = True
[mypy-graphene.types.scalars]
ignore_errors = True
[mypy-graphene.types.generic]
ignore_errors = True
[mypy-graphene.types.tests.*]
ignore_errors = True
[mypy-graphene.relay.tests.*]
ignore_errors = True