Skip to content

Commit 7cfec55

Browse files
committed
Added mypy static checking
1 parent 19bf9b3 commit 7cfec55

File tree

10 files changed

+63
-5
lines changed

10 files changed

+63
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,4 @@ target/
8080
# Databases
8181
*.sqlite3
8282
.vscode
83+
.mypy_cache

.travis.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,19 @@ install:
2727
elif [ "$TEST_TYPE" = lint ]; then
2828
pip install flake8
2929
fi
30+
elif [ "$TEST_TYPE" = mypy ]; then
31+
pip install mypy
32+
fi
3033
script:
3134
- |
3235
if [ "$TEST_TYPE" = lint ]; then
3336
echo "Checking Python code lint."
3437
flake8 graphene
3538
exit
39+
elif [ "$TEST_TYPE" = mypy ]; then
40+
echo "Checking Python types."
41+
mypy graphene
42+
exit
3643
elif [ "$TEST_TYPE" = build ]; then
3744
py.test --cov=graphene graphene examples
3845
fi
@@ -51,6 +58,8 @@ matrix:
5158
include:
5259
- python: '2.7'
5360
env: TEST_TYPE=lint
61+
- python: '3.6'
62+
env: TEST_TYPE=mypy
5463
deploy:
5564
provider: pypi
5665
user: syrusakbary

graphene/pyutils/init_subclass.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ def __init__(cls, name, bases, ns, **kwargs):
1616
if hasattr(super_class, '__init_subclass__'):
1717
super_class.__init_subclass__.__func__(cls, **kwargs)
1818
else:
19-
InitSubclassMeta = type
19+
InitSubclassMeta = type # type: ignore

graphene/types/inputobjecttype.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@
66
from .utils import yank_fields_from_attrs
77

88

9+
# For static type checking with Mypy
10+
MYPY = False
11+
if MYPY:
12+
from typing import Dict, Callable
13+
14+
915
class InputObjectTypeOptions(BaseOptions):
10-
fields = None # type: Dict[str, Field]
16+
fields = None # type: Dict[str, InputField]
1117
create_container = None # type: Callable
1218

1319

graphene/types/interface.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
from .field import Field
55
from .utils import yank_fields_from_attrs
66

7+
# For static type checking with Mypy
8+
MYPY = False
9+
if MYPY:
10+
from typing import Dict
11+
712

813
class InterfaceOptions(BaseOptions):
914
fields = None # type: Dict[str, Field]

graphene/types/mutation.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,17 @@
88
from ..utils.deprecated import warn_deprecation
99

1010

11+
# For static type checking with Mypy
12+
MYPY = False
13+
if MYPY:
14+
from .argument import Argument
15+
from typing import Dict, Type, Callable
16+
17+
1118
class MutationOptions(ObjectTypeOptions):
1219
arguments = None # type: Dict[str, Argument]
1320
output = None # type: Type[ObjectType]
14-
resolver = None # type: Function
21+
resolver = None # type: Callable
1522

1623

1724
class Mutation(ObjectType):

graphene/types/objecttype.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@
55
from .interface import Interface
66
from .utils import yank_fields_from_attrs
77

8+
# For static type checking with Mypy
9+
MYPY = False
10+
if MYPY:
11+
from typing import Dict, Iterable, Type
12+
813

914
class ObjectTypeOptions(BaseOptions):
1015
fields = None # type: Dict[str, Field]
11-
interfaces = () # type: List[Type[Interface]]
16+
interfaces = () # type: Iterable[Type[Interface]]
1217

1318

1419
class ObjectType(BaseType):

graphene/types/scalars.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class Float(Scalar):
8686

8787
@staticmethod
8888
def coerce_float(value):
89+
# type: (Any) -> float
8990
try:
9091
return float(value)
9192
except ValueError:

graphene/types/union.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,15 @@
22
from .unmountedtype import UnmountedType
33

44

5+
# For static type checking with Mypy
6+
MYPY = False
7+
if MYPY:
8+
from .objecttype import ObjectType
9+
from typing import Iterable, Type
10+
11+
512
class UnionOptions(BaseOptions):
6-
types = () # type: List[Type[ObjectType]]
13+
types = () # type: Iterable[Type[ObjectType]]
714

815

916
class Union(UnmountedType, BaseType):

mypy.ini

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[mypy]
2+
ignore_missing_imports = True
3+
4+
[mypy-graphene.pyutils.*]
5+
ignore_errors = True
6+
7+
[mypy-graphene.types.scalars]
8+
ignore_errors = True
9+
10+
[mypy-graphene.types.generic]
11+
ignore_errors = True
12+
13+
[mypy-graphene.types.tests.*]
14+
ignore_errors = True
15+
16+
[mypy-graphene.relay.tests.*]
17+
ignore_errors = True

0 commit comments

Comments
 (0)