mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-23 18:13:54 +03:00
Added mypy static checking
This commit is contained in:
parent
19bf9b3713
commit
7cfec55410
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -80,3 +80,4 @@ target/
|
||||||
# Databases
|
# Databases
|
||||||
*.sqlite3
|
*.sqlite3
|
||||||
.vscode
|
.vscode
|
||||||
|
.mypy_cache
|
||||||
|
|
|
@ -27,12 +27,19 @@ install:
|
||||||
elif [ "$TEST_TYPE" = lint ]; then
|
elif [ "$TEST_TYPE" = lint ]; then
|
||||||
pip install flake8
|
pip install flake8
|
||||||
fi
|
fi
|
||||||
|
elif [ "$TEST_TYPE" = mypy ]; then
|
||||||
|
pip install mypy
|
||||||
|
fi
|
||||||
script:
|
script:
|
||||||
- |
|
- |
|
||||||
if [ "$TEST_TYPE" = lint ]; then
|
if [ "$TEST_TYPE" = lint ]; then
|
||||||
echo "Checking Python code lint."
|
echo "Checking Python code lint."
|
||||||
flake8 graphene
|
flake8 graphene
|
||||||
exit
|
exit
|
||||||
|
elif [ "$TEST_TYPE" = mypy ]; then
|
||||||
|
echo "Checking Python types."
|
||||||
|
mypy graphene
|
||||||
|
exit
|
||||||
elif [ "$TEST_TYPE" = build ]; then
|
elif [ "$TEST_TYPE" = build ]; then
|
||||||
py.test --cov=graphene graphene examples
|
py.test --cov=graphene graphene examples
|
||||||
fi
|
fi
|
||||||
|
@ -51,6 +58,8 @@ matrix:
|
||||||
include:
|
include:
|
||||||
- python: '2.7'
|
- python: '2.7'
|
||||||
env: TEST_TYPE=lint
|
env: TEST_TYPE=lint
|
||||||
|
- python: '3.6'
|
||||||
|
env: TEST_TYPE=mypy
|
||||||
deploy:
|
deploy:
|
||||||
provider: pypi
|
provider: pypi
|
||||||
user: syrusakbary
|
user: syrusakbary
|
||||||
|
|
|
@ -16,4 +16,4 @@ if not is_init_subclass_available:
|
||||||
if hasattr(super_class, '__init_subclass__'):
|
if hasattr(super_class, '__init_subclass__'):
|
||||||
super_class.__init_subclass__.__func__(cls, **kwargs)
|
super_class.__init_subclass__.__func__(cls, **kwargs)
|
||||||
else:
|
else:
|
||||||
InitSubclassMeta = type
|
InitSubclassMeta = type # type: ignore
|
||||||
|
|
|
@ -6,8 +6,14 @@ from .unmountedtype import UnmountedType
|
||||||
from .utils import yank_fields_from_attrs
|
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):
|
class InputObjectTypeOptions(BaseOptions):
|
||||||
fields = None # type: Dict[str, Field]
|
fields = None # type: Dict[str, InputField]
|
||||||
create_container = None # type: Callable
|
create_container = None # type: Callable
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,11 @@ from .base import BaseOptions, BaseType
|
||||||
from .field import Field
|
from .field import Field
|
||||||
from .utils import yank_fields_from_attrs
|
from .utils import yank_fields_from_attrs
|
||||||
|
|
||||||
|
# For static type checking with Mypy
|
||||||
|
MYPY = False
|
||||||
|
if MYPY:
|
||||||
|
from typing import Dict
|
||||||
|
|
||||||
|
|
||||||
class InterfaceOptions(BaseOptions):
|
class InterfaceOptions(BaseOptions):
|
||||||
fields = None # type: Dict[str, Field]
|
fields = None # type: Dict[str, Field]
|
||||||
|
|
|
@ -8,10 +8,17 @@ from .utils import yank_fields_from_attrs
|
||||||
from ..utils.deprecated import warn_deprecation
|
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):
|
class MutationOptions(ObjectTypeOptions):
|
||||||
arguments = None # type: Dict[str, Argument]
|
arguments = None # type: Dict[str, Argument]
|
||||||
output = None # type: Type[ObjectType]
|
output = None # type: Type[ObjectType]
|
||||||
resolver = None # type: Function
|
resolver = None # type: Callable
|
||||||
|
|
||||||
|
|
||||||
class Mutation(ObjectType):
|
class Mutation(ObjectType):
|
||||||
|
|
|
@ -5,10 +5,15 @@ from .field import Field
|
||||||
from .interface import Interface
|
from .interface import Interface
|
||||||
from .utils import yank_fields_from_attrs
|
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):
|
class ObjectTypeOptions(BaseOptions):
|
||||||
fields = None # type: Dict[str, Field]
|
fields = None # type: Dict[str, Field]
|
||||||
interfaces = () # type: List[Type[Interface]]
|
interfaces = () # type: Iterable[Type[Interface]]
|
||||||
|
|
||||||
|
|
||||||
class ObjectType(BaseType):
|
class ObjectType(BaseType):
|
||||||
|
|
|
@ -86,6 +86,7 @@ class Float(Scalar):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def coerce_float(value):
|
def coerce_float(value):
|
||||||
|
# type: (Any) -> float
|
||||||
try:
|
try:
|
||||||
return float(value)
|
return float(value)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
|
|
@ -2,8 +2,15 @@ from .base import BaseOptions, BaseType
|
||||||
from .unmountedtype import UnmountedType
|
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):
|
class UnionOptions(BaseOptions):
|
||||||
types = () # type: List[Type[ObjectType]]
|
types = () # type: Iterable[Type[ObjectType]]
|
||||||
|
|
||||||
|
|
||||||
class Union(UnmountedType, BaseType):
|
class Union(UnmountedType, BaseType):
|
||||||
|
|
17
mypy.ini
Normal file
17
mypy.ini
Normal 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
|
Loading…
Reference in New Issue
Block a user