Skip to content

Added Static typing using type annotations and mypy #193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jul 2, 2018
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,7 @@ target/

# OS X
.DS_Store
/.mypy_cache
.pyre
/.vscode
/type_info.json
20 changes: 4 additions & 16 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,6 @@ sudo: false
python:
- 2.7
# - "pypy-5.3.1"
before_install:
- |
if [ "$TRAVIS_PYTHON_VERSION" = "pypy" ]; then
export PYENV_ROOT="$HOME/.pyenv"
if [ -f "$PYENV_ROOT/bin/pyenv" ]; then
cd "$PYENV_ROOT" && git pull
else
rm -rf "$PYENV_ROOT" && git clone --depth 1 https://github.com/yyuu/pyenv.git "$PYENV_ROOT"
fi
export PYPY_VERSION="4.0.1"
"$PYENV_ROOT/bin/pyenv" install "pypy-$PYPY_VERSION"
virtualenv --python="$PYENV_ROOT/versions/pypy-$PYPY_VERSION/bin/python" "$HOME/virtualenvs/pypy-$PYPY_VERSION"
source "$HOME/virtualenvs/pypy-$PYPY_VERSION/bin/activate"
fi
install:
- pip install -e .[test]
- pip install flake8
Expand All @@ -33,10 +19,12 @@ matrix:
script:
- py.test --cov=graphql graphql tests tests_py35
- python: '3.6'
after_install:
- pip install pytest-asyncio
install:
- pip install -e .[test]
- pip install pytest-asyncio mypy
script:
- py.test --cov=graphql graphql tests tests_py35
- mypy graphql --ignore-missing-imports
- python: '2.7'

deploy:
Expand Down
30 changes: 30 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Configuration for pytest to automatically collect types.
# Thanks to Guilherme Salgado.
import pytest

try:
import pyannotate_runtime
PYANOTATE_PRESENT = True
except ImportError:
PYANOTATE_PRESENT = False

if PYANOTATE_PRESENT:
def pytest_collection_finish(session):
"""Handle the pytest collection finish hook: configure pyannotate.
Explicitly delay importing `collect_types` until all tests have
been collected. This gives gevent a chance to monkey patch the
world before importing pyannotate.
"""
from pyannotate_runtime import collect_types
collect_types.init_types_collection()

@pytest.fixture(autouse=True)
def collect_types_fixture():
from pyannotate_runtime import collect_types
collect_types.resume()
yield
collect_types.pause()

def pytest_sessionfinish(session, exitstatus):
from pyannotate_runtime import collect_types
collect_types.dump_stats("type_info.json")
Loading