From 3d12895fb62105efb7ca686dc7bd382ef4857816 Mon Sep 17 00:00:00 2001 From: Daniel Gallagher Date: Fri, 8 Jun 2018 20:52:14 -0700 Subject: [PATCH 1/9] Have travis use tox --- .travis.yml | 49 ++++++++++--------------------------------------- 1 file changed, 10 insertions(+), 39 deletions(-) diff --git a/.travis.yml b/.travis.yml index e8b55782..0aede16c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,43 +1,14 @@ language: python -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 -script: -- flake8 -- py.test --cov=graphql graphql tests -after_success: -- coveralls -matrix: - include: - - python: '3.5' - after_install: - - pip install pytest-asyncio - script: - - py.test --cov=graphql graphql tests tests_py35 - - python: '3.6' - after_install: - - pip install pytest-asyncio - script: - - py.test --cov=graphql graphql tests tests_py35 - - python: '2.7' +python: 3.6 +env: # These should match the tox env list. + - TOXENV=flake8 + - TOXENV=py27 + - TOXENV=py33 + - TOXENV=py34 + - TOXENV=py35 + - TOXENV=py36 + - TOXENV=pypy + - TOXENV=pre-commit deploy: provider: pypi From 3833a80ec0d8643861ff8027579a25b8938384dc Mon Sep 17 00:00:00 2001 From: Daniel Gallagher Date: Fri, 8 Jun 2018 20:59:19 -0700 Subject: [PATCH 2/9] Update travis tox usage more --- .travis.yml | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0aede16c..5292f348 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,26 @@ language: python -python: 3.6 -env: # These should match the tox env list. - - TOXENV=flake8 - - TOXENV=py27 - - TOXENV=py33 - - TOXENV=py34 - - TOXENV=py35 - - TOXENV=py36 - - TOXENV=pypy - - TOXENV=pre-commit - +matrix: + include: + - env: TOXENV=py27 + - env: TOXENV=py33 + python: 3.3 + - env: TOXENV=py34 + python: 3.4 + - env: TOXENV=py35 + python: 3.5 + - env: TOXENV=py36 + python: 3.6 + - env: TOXENV=pypy + python: pypy-5.7.1 + - env: TOXENV=pre-commit + python: 3.6 +install: pip install coveralls tox +script: tox +after_success: coveralls +cache: + directories: + - $HOME/.cache/pip + - $HOME/.cache/pre-commit deploy: provider: pypi user: syrusakbary From 415a78ad4f63eec47ad70ab24659345fc274deb4 Mon Sep 17 00:00:00 2001 From: Daniel Gallagher Date: Fri, 8 Jun 2018 21:10:37 -0700 Subject: [PATCH 3/9] Drop py33 support --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5292f348..4772256d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,8 +2,6 @@ language: python matrix: include: - env: TOXENV=py27 - - env: TOXENV=py33 - python: 3.3 - env: TOXENV=py34 python: 3.4 - env: TOXENV=py35 From 0fd5d6db624f28d412ba65a8f6c3d2ed3a9291d7 Mon Sep 17 00:00:00 2001 From: Daniel Gallagher Date: Fri, 8 Jun 2018 21:10:57 -0700 Subject: [PATCH 4/9] Run pre-commit on all files --- graphql/backend/base.py | 7 ++-- graphql/backend/cache.py | 3 +- graphql/backend/compiled.py | 1 + graphql/backend/core.py | 6 +-- graphql/backend/quiver_cloud.py | 4 +- graphql/backend/tests/schema.py | 5 +-- graphql/backend/tests/test_base.py | 3 +- graphql/backend/tests/test_cache.py | 5 ++- graphql/backend/tests/test_core.py | 3 +- graphql/backend/tests/test_decider.py | 3 +- graphql/error/base.py | 1 + graphql/error/tests/test_base.py | 3 +- graphql/execution/base.py | 16 +++---- graphql/execution/executor.py | 12 +++--- graphql/execution/executors/asyncio_utils.py | 9 ++-- graphql/execution/tests/test_benchmark.py | 1 + graphql/execution/tests/test_dataloader.py | 9 ++-- graphql/execution/tests/test_executor.py | 8 ++-- .../execution/tests/test_executor_thread.py | 14 +++---- graphql/execution/tests/test_located_error.py | 8 +--- graphql/execution/tests/test_nonnull.py | 42 +++++++++---------- graphql/execution/tests/test_subscribe.py | 5 ++- graphql/execution/tests/test_variables.py | 6 +-- graphql/graphql.py | 5 ++- graphql/language/tests/test_lexer.py | 4 +- graphql/language/tests/test_parser.py | 4 +- graphql/language/tests/test_printer.py | 4 +- graphql/language/tests/test_schema_parser.py | 4 +- graphql/language/tests/test_schema_printer.py | 4 +- .../tests/test_default_ordered_dict.py | 4 +- graphql/type/tests/test_definition.py | 6 +-- graphql/type/tests/test_enum_type.py | 3 +- graphql/type/tests/test_serialization.py | 4 +- graphql/type/tests/test_validation.py | 4 +- graphql/type/typemap.py | 9 ++-- graphql/utils/tests/test_build_ast_schema.py | 4 +- .../utils/tests/test_build_client_schema.py | 4 +- graphql/utils/tests/test_extend_schema.py | 4 +- tox.ini | 4 +- 39 files changed, 122 insertions(+), 123 deletions(-) diff --git a/graphql/backend/base.py b/graphql/backend/base.py index 42598668..9b4d7332 100644 --- a/graphql/backend/base.py +++ b/graphql/backend/base.py @@ -1,9 +1,10 @@ -from ..pyutils.cached_property import cached_property -from ..language import ast - from abc import ABCMeta, abstractmethod + import six +from ..language import ast +from ..pyutils.cached_property import cached_property + class GraphQLBackend(six.with_metaclass(ABCMeta)): @abstractmethod diff --git a/graphql/backend/cache.py b/graphql/backend/cache.py index aa1631fb..56239636 100644 --- a/graphql/backend/cache.py +++ b/graphql/backend/cache.py @@ -1,7 +1,8 @@ from hashlib import sha1 + from six import string_types -from ..type import GraphQLSchema +from ..type import GraphQLSchema from .base import GraphQLBackend _cached_schemas = {} diff --git a/graphql/backend/compiled.py b/graphql/backend/compiled.py index f074cecf..75c19ec3 100644 --- a/graphql/backend/compiled.py +++ b/graphql/backend/compiled.py @@ -1,4 +1,5 @@ from six import string_types + from .base import GraphQLDocument diff --git a/graphql/backend/core.py b/graphql/backend/core.py index 7cbb9d3e..a495d018 100644 --- a/graphql/backend/core.py +++ b/graphql/backend/core.py @@ -1,11 +1,11 @@ from functools import partial + from six import string_types -from ..execution import execute, ExecutionResult -from ..language.base import parse, print_ast +from ..execution import ExecutionResult, execute from ..language import ast +from ..language.base import parse, print_ast from ..validation import validate - from .base import GraphQLBackend, GraphQLDocument diff --git a/graphql/backend/quiver_cloud.py b/graphql/backend/quiver_cloud.py index ca198dee..f760c5fc 100644 --- a/graphql/backend/quiver_cloud.py +++ b/graphql/backend/quiver_cloud.py @@ -6,12 +6,12 @@ "You can install it using: pip install requests" ) -from ..utils.schema_printer import print_schema +from six import urlparse +from ..utils.schema_printer import print_schema from .base import GraphQLBackend from .compiled import GraphQLCompiledDocument -from six import urlparse GRAPHQL_QUERY = """ mutation($schemaDsl: String!, $query: String!) { diff --git a/graphql/backend/tests/schema.py b/graphql/backend/tests/schema.py index a01f0d62..b747c4a9 100644 --- a/graphql/backend/tests/schema.py +++ b/graphql/backend/tests/schema.py @@ -1,6 +1,5 @@ -from graphql.type import (GraphQLField, GraphQLObjectType, - GraphQLSchema, GraphQLString) - +from graphql.type import (GraphQLField, GraphQLObjectType, GraphQLSchema, + GraphQLString) Query = GraphQLObjectType('Query', lambda: { 'hello': GraphQLField(GraphQLString, resolver=lambda *_: "World"), diff --git a/graphql/backend/tests/test_base.py b/graphql/backend/tests/test_base.py index 063f3e89..f7723334 100644 --- a/graphql/backend/tests/test_base.py +++ b/graphql/backend/tests/test_base.py @@ -1,5 +1,6 @@ import pytest -from .. import get_default_backend, set_default_backend, GraphQLCoreBackend + +from .. import GraphQLCoreBackend, get_default_backend, set_default_backend def test_get_default_backend_returns_core_by_default(): diff --git a/graphql/backend/tests/test_cache.py b/graphql/backend/tests/test_cache.py index a2814691..f9cb11f4 100644 --- a/graphql/backend/tests/test_cache.py +++ b/graphql/backend/tests/test_cache.py @@ -2,11 +2,12 @@ # -*- coding: utf-8 -*- """Tests for `graphql.backend.cache` module.""" +from graphql.execution.executors.sync import SyncExecutor + import pytest -from ..core import GraphQLCoreBackend from ..cache import GraphQLCachedBackend -from graphql.execution.executors.sync import SyncExecutor +from ..core import GraphQLCoreBackend from .schema import schema diff --git a/graphql/backend/tests/test_core.py b/graphql/backend/tests/test_core.py index 43fb8357..43265d61 100644 --- a/graphql/backend/tests/test_core.py +++ b/graphql/backend/tests/test_core.py @@ -2,9 +2,10 @@ # -*- coding: utf-8 -*- """Tests for `graphql.backend.core` module.""" -import pytest from graphql.execution.executors.sync import SyncExecutor +import pytest + from ..base import GraphQLBackend, GraphQLDocument from ..core import GraphQLCoreBackend from .schema import schema diff --git a/graphql/backend/tests/test_decider.py b/graphql/backend/tests/test_decider.py index 7ec38a4b..30dc3ebf 100644 --- a/graphql/backend/tests/test_decider.py +++ b/graphql/backend/tests/test_decider.py @@ -5,10 +5,9 @@ import pytest from ..base import GraphQLBackend, GraphQLDocument -from ..core import GraphQLCoreBackend from ..cache import GraphQLCachedBackend +from ..core import GraphQLCoreBackend from ..decider import GraphQLDeciderBackend - from .schema import schema diff --git a/graphql/error/base.py b/graphql/error/base.py index b894ecd5..b94a691d 100644 --- a/graphql/error/base.py +++ b/graphql/error/base.py @@ -1,4 +1,5 @@ import six + from ..language.location import get_location diff --git a/graphql/error/tests/test_base.py b/graphql/error/tests/test_base.py index c686a0f6..75318ce9 100644 --- a/graphql/error/tests/test_base.py +++ b/graphql/error/tests/test_base.py @@ -1,4 +1,3 @@ -import pytest import traceback from graphql.execution import execute @@ -6,6 +5,8 @@ from graphql.type import (GraphQLField, GraphQLObjectType, GraphQLSchema, GraphQLString) +import pytest + def test_raise(): ast = parse('query Example { a }') diff --git a/graphql/execution/base.py b/graphql/execution/base.py index 266771ac..55c32e54 100644 --- a/graphql/execution/base.py +++ b/graphql/execution/base.py @@ -1,15 +1,9 @@ # We keep the following imports to preserve compatibility -from .utils import ( - ExecutionContext, - SubscriberExecutionContext, - get_operation_root_type, - collect_fields, - should_include_node, - does_fragment_condition_match, - get_field_entry_key, - default_resolve_fn, - get_field_def -) +from .utils import (ExecutionContext, SubscriberExecutionContext, + collect_fields, default_resolve_fn, + does_fragment_condition_match, get_field_def, + get_field_entry_key, get_operation_root_type, + should_include_node) class ExecutionResult(object): diff --git a/graphql/execution/executor.py b/graphql/execution/executor.py index fd5cea65..a31014a5 100644 --- a/graphql/execution/executor.py +++ b/graphql/execution/executor.py @@ -3,21 +3,21 @@ import logging import sys import warnings -from rx import Observable +from promise import Promise, is_thenable, promise_for_dict +from rx import Observable from six import string_types -from promise import Promise, promise_for_dict, is_thenable from ..error import GraphQLError, GraphQLLocatedError from ..pyutils.default_ordered_dict import DefaultOrderedDict from ..pyutils.ordereddict import OrderedDict -from ..utils.undefined import Undefined from ..type import (GraphQLEnumType, GraphQLInterfaceType, GraphQLList, GraphQLNonNull, GraphQLObjectType, GraphQLScalarType, GraphQLSchema, GraphQLUnionType) +from ..utils.undefined import Undefined from .base import (ExecutionContext, ExecutionResult, ResolveInfo, - collect_fields, default_resolve_fn, get_field_def, - get_operation_root_type, SubscriberExecutionContext) + SubscriberExecutionContext, collect_fields, + default_resolve_fn, get_field_def, get_operation_root_type) from .executors.sync import SyncExecutor from .middleware import MiddlewareManager @@ -147,7 +147,7 @@ def execute_field_callback(results, response_name): source_value, field_asts, None, - path+[response_name] + path + [response_name] ) if result is Undefined: return results diff --git a/graphql/execution/executors/asyncio_utils.py b/graphql/execution/executors/asyncio_utils.py index 836d90d7..d5e0464c 100644 --- a/graphql/execution/executors/asyncio_utils.py +++ b/graphql/execution/executors/asyncio_utils.py @@ -1,11 +1,10 @@ -from inspect import isasyncgen from asyncio import ensure_future -from rx import Observable, AnonymousObserver -from rx.core import ObservableBase, Disposable, ObserverBase +from inspect import isasyncgen +from rx import AnonymousObserver, Observable from rx.concurrency import current_thread_scheduler - -from rx.core import Observer, Observable, Disposable +from rx.core import (Disposable, Observable, ObservableBase, Observer, + ObserverBase) from rx.core.anonymousobserver import AnonymousObserver from rx.core.autodetachobserver import AutoDetachObserver diff --git a/graphql/execution/tests/test_benchmark.py b/graphql/execution/tests/test_benchmark.py index 8c5e8d75..2704bff4 100644 --- a/graphql/execution/tests/test_benchmark.py +++ b/graphql/execution/tests/test_benchmark.py @@ -3,6 +3,7 @@ from graphql import (GraphQLField, GraphQLInt, GraphQLList, GraphQLObjectType, GraphQLSchema, Source, execute, parse) + # from graphql.execution import executor # executor.use_experimental_executor = True diff --git a/graphql/execution/tests/test_dataloader.py b/graphql/execution/tests/test_dataloader.py index 7fd4611e..195c674e 100644 --- a/graphql/execution/tests/test_dataloader.py +++ b/graphql/execution/tests/test_dataloader.py @@ -1,10 +1,11 @@ -import pytest +from graphql import (GraphQLArgument, GraphQLField, GraphQLID, GraphQLNonNull, + GraphQLObjectType, GraphQLSchema, execute, parse) +from graphql.execution.executors.sync import SyncExecutor +from graphql.execution.executors.thread import ThreadExecutor from promise import Promise from promise.dataloader import DataLoader -from graphql import GraphQLObjectType, GraphQLField, GraphQLID, GraphQLArgument, GraphQLNonNull, GraphQLSchema, parse, execute -from graphql.execution.executors.sync import SyncExecutor -from graphql.execution.executors.thread import ThreadExecutor +import pytest @pytest.mark.parametrize("executor", [ diff --git a/graphql/execution/tests/test_executor.py b/graphql/execution/tests/test_executor.py index 706c1f9a..79b46413 100644 --- a/graphql/execution/tests/test_executor.py +++ b/graphql/execution/tests/test_executor.py @@ -1,15 +1,15 @@ import json -from pytest import raises - from graphql.error import GraphQLError from graphql.execution import MiddlewareManager, execute from graphql.language.parser import parse from graphql.type import (GraphQLArgument, GraphQLBoolean, GraphQLField, - GraphQLInt, GraphQLList, GraphQLObjectType, - GraphQLSchema, GraphQLString, GraphQLNonNull, GraphQLID) + GraphQLID, GraphQLInt, GraphQLList, GraphQLNonNull, + GraphQLObjectType, GraphQLSchema, GraphQLString) from promise import Promise +from pytest import raises + def test_executes_arbitary_code(): class Data(object): diff --git a/graphql/execution/tests/test_executor_thread.py b/graphql/execution/tests/test_executor_thread.py index 5b44255d..49b38a9a 100644 --- a/graphql/execution/tests/test_executor_thread.py +++ b/graphql/execution/tests/test_executor_thread.py @@ -206,13 +206,13 @@ def handle_results(result): 'syncReturnErrorList': ['sync0', None, 'sync2', None] } assert sorted(list(map(format_error, result.errors)), key=sort_key) == sorted([ - {'locations': [{'line': 4, 'column': 9}], 'path':['syncError'], 'message': 'Error getting syncError'}, - {'locations': [{'line': 5, 'column': 9}], 'path':['syncReturnError'], 'message': 'Error getting syncReturnError'}, - {'locations': [{'line': 6, 'column': 9}], 'path':['syncReturnErrorList', 1], 'message': 'Error getting syncReturnErrorList1'}, - {'locations': [{'line': 6, 'column': 9}], 'path':['syncReturnErrorList', 3], 'message': 'Error getting syncReturnErrorList3'}, - {'locations': [{'line': 8, 'column': 9}], 'path':['asyncReject'], 'message': 'Error getting asyncReject'}, - {'locations': [{'line': 9, 'column': 9}], 'path':['asyncEmptyReject'], 'message': 'An unknown error occurred.'}, - {'locations': [{'line': 10, 'column': 9}], 'path':['asyncReturnError'], 'message': 'Error getting asyncReturnError'} + {'locations': [{'line': 4, 'column': 9}], 'path': ['syncError'], 'message': 'Error getting syncError'}, + {'locations': [{'line': 5, 'column': 9}], 'path': ['syncReturnError'], 'message': 'Error getting syncReturnError'}, + {'locations': [{'line': 6, 'column': 9}], 'path': ['syncReturnErrorList', 1], 'message': 'Error getting syncReturnErrorList1'}, + {'locations': [{'line': 6, 'column': 9}], 'path': ['syncReturnErrorList', 3], 'message': 'Error getting syncReturnErrorList3'}, + {'locations': [{'line': 8, 'column': 9}], 'path': ['asyncReject'], 'message': 'Error getting asyncReject'}, + {'locations': [{'line': 9, 'column': 9}], 'path': ['asyncEmptyReject'], 'message': 'An unknown error occurred.'}, + {'locations': [{'line': 10, 'column': 9}], 'path': ['asyncReturnError'], 'message': 'Error getting asyncReturnError'} ], key=sort_key) handle_results(execute(schema, ast, Data(), executor=ThreadExecutor())) diff --git a/graphql/execution/tests/test_located_error.py b/graphql/execution/tests/test_located_error.py index df61f257..8b51452b 100644 --- a/graphql/execution/tests/test_located_error.py +++ b/graphql/execution/tests/test_located_error.py @@ -1,11 +1,7 @@ # coding: utf-8 -from graphql import GraphQLField -from graphql import GraphQLObjectType -from graphql import GraphQLSchema -from graphql import GraphQLString -from graphql import execute -from graphql import parse +from graphql import (GraphQLField, GraphQLObjectType, GraphQLSchema, + GraphQLString, execute, parse) from graphql.error import GraphQLLocatedError diff --git a/graphql/execution/tests/test_nonnull.py b/graphql/execution/tests/test_nonnull.py index b72e2f30..6a9c4256 100644 --- a/graphql/execution/tests/test_nonnull.py +++ b/graphql/execution/tests/test_nonnull.py @@ -320,27 +320,27 @@ def test_nulls_the_first_nullable_object_after_a_field_throws_in_a_long_chain_of 'errors': [{'locations': [{'column': 19, 'line': 8}], 'path': [ 'nest', 'nonNullNest', 'nonNullPromiseNest', - 'nonNullNest', 'nonNullPromiseNest', 'nonNullSync' - ], - 'message': str(non_null_sync_error)}, - {'locations': [{'column': 19, 'line': 19}], - 'path': [ - 'promiseNest', 'nonNullNest', 'nonNullPromiseNest', - 'nonNullNest', 'nonNullPromiseNest', 'nonNullSync' - ], - 'message': str(non_null_sync_error)}, - {'locations': [{'column': 19, 'line': 30}], - 'path': [ - 'anotherNest', 'nonNullNest', 'nonNullPromiseNest', - 'nonNullNest', 'nonNullPromiseNest', 'nonNullPromise' - ], - 'message': str(non_null_promise_error)}, - {'locations': [{'column': 19, 'line': 41}], - 'path': [ - 'anotherPromiseNest', 'nonNullNest', 'nonNullPromiseNest', - 'nonNullNest', 'nonNullPromiseNest', 'nonNullPromise' - ], - 'message': str(non_null_promise_error)}] + 'nonNullNest', 'nonNullPromiseNest', 'nonNullSync' + ], + 'message': str(non_null_sync_error)}, + {'locations': [{'column': 19, 'line': 19}], + 'path': [ + 'promiseNest', 'nonNullNest', 'nonNullPromiseNest', + 'nonNullNest', 'nonNullPromiseNest', 'nonNullSync' + ], + 'message': str(non_null_sync_error)}, + {'locations': [{'column': 19, 'line': 30}], + 'path': [ + 'anotherNest', 'nonNullNest', 'nonNullPromiseNest', + 'nonNullNest', 'nonNullPromiseNest', 'nonNullPromise' + ], + 'message': str(non_null_promise_error)}, + {'locations': [{'column': 19, 'line': 41}], + 'path': [ + 'anotherPromiseNest', 'nonNullNest', 'nonNullPromiseNest', + 'nonNullNest', 'nonNullPromiseNest', 'nonNullPromise' + ], + 'message': str(non_null_promise_error)}] }) diff --git a/graphql/execution/tests/test_subscribe.py b/graphql/execution/tests/test_subscribe.py index 2acb56a9..34fe5ead 100644 --- a/graphql/execution/tests/test_subscribe.py +++ b/graphql/execution/tests/test_subscribe.py @@ -1,7 +1,10 @@ from collections import OrderedDict, namedtuple + +from graphql import (GraphQLBoolean, GraphQLField, GraphQLInt, GraphQLList, + GraphQLObjectType, GraphQLSchema, GraphQLString, graphql, + parse, subscribe) from rx import Observable, Observer from rx.subjects import Subject -from graphql import parse, GraphQLObjectType, GraphQLString, GraphQLBoolean, GraphQLInt, GraphQLField, GraphQLList, GraphQLSchema, graphql, subscribe Email = namedtuple('Email', 'from_,subject,message,unread') diff --git a/graphql/execution/tests/test_variables.py b/graphql/execution/tests/test_variables.py index 7f001caa..67597ca0 100644 --- a/graphql/execution/tests/test_variables.py +++ b/graphql/execution/tests/test_variables.py @@ -1,16 +1,16 @@ import json from collections import OrderedDict -from pytest import raises - from graphql.error import GraphQLError, format_error from graphql.execution import execute from graphql.language.parser import parse -from graphql.type import (GraphQLArgument, GraphQLField, GraphQLBoolean, +from graphql.type import (GraphQLArgument, GraphQLBoolean, GraphQLField, GraphQLInputObjectField, GraphQLInputObjectType, GraphQLList, GraphQLNonNull, GraphQLObjectType, GraphQLScalarType, GraphQLSchema, GraphQLString) +from pytest import raises + TestComplexScalar = GraphQLScalarType( name='ComplexScalar', serialize=lambda v: 'SerializedValue' if v == 'DeserializedValue' else None, diff --git a/graphql/graphql.py b/graphql/graphql.py index 8dc4a906..fdd3029b 100644 --- a/graphql/graphql.py +++ b/graphql/graphql.py @@ -1,7 +1,8 @@ -from .execution import ExecutionResult +from promise import promisify + from .backend import get_default_backend +from .execution import ExecutionResult -from promise import promisify # This is the primary entry point function for fulfilling GraphQL operations # by parsing, validating, and executing a GraphQL document along side a diff --git a/graphql/language/tests/test_lexer.py b/graphql/language/tests/test_lexer.py index 44283355..2ad82f27 100644 --- a/graphql/language/tests/test_lexer.py +++ b/graphql/language/tests/test_lexer.py @@ -1,9 +1,9 @@ -from pytest import raises - from graphql.error import GraphQLSyntaxError from graphql.language.lexer import Lexer, Token, TokenKind from graphql.language.source import Source +from pytest import raises + def lex_one(s): return Lexer(Source(s)).next_token() diff --git a/graphql/language/tests/test_parser.py b/graphql/language/tests/test_parser.py index 7d587db8..88e6e7ae 100644 --- a/graphql/language/tests/test_parser.py +++ b/graphql/language/tests/test_parser.py @@ -1,11 +1,11 @@ -from pytest import raises - from graphql.error import GraphQLSyntaxError from graphql.language import ast from graphql.language.location import SourceLocation from graphql.language.parser import Loc, parse from graphql.language.source import Source +from pytest import raises + from .fixtures import KITCHEN_SINK diff --git a/graphql/language/tests/test_printer.py b/graphql/language/tests/test_printer.py index 5d8ce7ea..56829d6c 100644 --- a/graphql/language/tests/test_printer.py +++ b/graphql/language/tests/test_printer.py @@ -1,11 +1,11 @@ import copy -from pytest import raises - from graphql.language.ast import Field, Name from graphql.language.parser import parse from graphql.language.printer import print_ast +from pytest import raises + from .fixtures import KITCHEN_SINK diff --git a/graphql/language/tests/test_schema_parser.py b/graphql/language/tests/test_schema_parser.py index 59c690c7..32a75094 100644 --- a/graphql/language/tests/test_schema_parser.py +++ b/graphql/language/tests/test_schema_parser.py @@ -1,10 +1,10 @@ -from pytest import raises - from graphql import Source, parse from graphql.error import GraphQLSyntaxError from graphql.language import ast from graphql.language.parser import Loc +from pytest import raises + def create_loc_fn(body): source = Source(body) diff --git a/graphql/language/tests/test_schema_printer.py b/graphql/language/tests/test_schema_printer.py index e565799e..63423b09 100644 --- a/graphql/language/tests/test_schema_printer.py +++ b/graphql/language/tests/test_schema_printer.py @@ -1,11 +1,11 @@ from copy import deepcopy -from pytest import raises - from graphql import parse from graphql.language import ast from graphql.language.printer import print_ast +from pytest import raises + from .fixtures import SCHEMA_KITCHEN_SINK diff --git a/graphql/pyutils/tests/test_default_ordered_dict.py b/graphql/pyutils/tests/test_default_ordered_dict.py index f1069137..dd9b17ba 100644 --- a/graphql/pyutils/tests/test_default_ordered_dict.py +++ b/graphql/pyutils/tests/test_default_ordered_dict.py @@ -1,10 +1,10 @@ import copy import pickle -from pytest import raises - from graphql.pyutils.default_ordered_dict import DefaultOrderedDict +from pytest import raises + def test_will_missing_will_set_value_from_factory(): d = DefaultOrderedDict(list) diff --git a/graphql/type/tests/test_definition.py b/graphql/type/tests/test_definition.py index 659ecfd4..89bc6245 100644 --- a/graphql/type/tests/test_definition.py +++ b/graphql/type/tests/test_definition.py @@ -1,7 +1,5 @@ from collections import OrderedDict -from py.test import raises - from graphql.type import (GraphQLArgument, GraphQLBoolean, GraphQLEnumType, GraphQLEnumValue, GraphQLField, GraphQLInputObjectField, GraphQLInputObjectType, @@ -10,6 +8,8 @@ GraphQLString, GraphQLUnionType) from graphql.type.definition import is_input_type, is_output_type +from py.test import raises + BlogImage = GraphQLObjectType('Image', { 'url': GraphQLField(GraphQLString), 'width': GraphQLField(GraphQLInt), @@ -142,7 +142,7 @@ def test_defines_an_enum_type_with_a_value_of_none(): assert value.deprecation_reason is None assert value.value is None - + def test_defines_an_object_type_with_deprecated_field(): TypeWithDeprecatedField = GraphQLObjectType('foo', fields={ 'bar': GraphQLField( diff --git a/graphql/type/tests/test_enum_type.py b/graphql/type/tests/test_enum_type.py index 65c9ae18..24124b56 100644 --- a/graphql/type/tests/test_enum_type.py +++ b/graphql/type/tests/test_enum_type.py @@ -1,11 +1,10 @@ from collections import OrderedDict -from rx import Observable - from graphql import graphql from graphql.type import (GraphQLArgument, GraphQLEnumType, GraphQLEnumValue, GraphQLField, GraphQLInt, GraphQLObjectType, GraphQLSchema, GraphQLString) +from rx import Observable ColorType = GraphQLEnumType( name='Color', diff --git a/graphql/type/tests/test_serialization.py b/graphql/type/tests/test_serialization.py index 4e5c09d0..bf1685a7 100644 --- a/graphql/type/tests/test_serialization.py +++ b/graphql/type/tests/test_serialization.py @@ -1,8 +1,8 @@ -import pytest - from graphql.type import (GraphQLBoolean, GraphQLFloat, GraphQLInt, GraphQLString) +import pytest + def test_serializes_output_int(): assert GraphQLInt.serialize(1) == 1 diff --git a/graphql/type/tests/test_validation.py b/graphql/type/tests/test_validation.py index 1b2e2cbf..fca65609 100644 --- a/graphql/type/tests/test_validation.py +++ b/graphql/type/tests/test_validation.py @@ -1,7 +1,5 @@ import re -from pytest import raises - from graphql.type import (GraphQLEnumType, GraphQLEnumValue, GraphQLField, GraphQLInputObjectField, GraphQLInputObjectType, GraphQLInterfaceType, GraphQLList, GraphQLNonNull, @@ -9,6 +7,8 @@ GraphQLString, GraphQLUnionType) from graphql.type.definition import GraphQLArgument +from pytest import raises + _none = lambda *args: None _true = lambda *args: True _false = lambda *args: False diff --git a/graphql/type/typemap.py b/graphql/type/typemap.py index 1bad09c1..cb0a24fc 100644 --- a/graphql/type/typemap.py +++ b/graphql/type/typemap.py @@ -2,11 +2,10 @@ from functools import reduce from ..utils.type_comparators import is_equal_type, is_type_sub_type_of -from .definition import (GraphQLArgument, - GraphQLInputObjectField, GraphQLInputObjectType, - GraphQLInterfaceType, GraphQLList, GraphQLNonNull, - GraphQLObjectType, GraphQLUnionType, is_input_type, - is_output_type) +from .definition import (GraphQLArgument, GraphQLInputObjectField, + GraphQLInputObjectType, GraphQLInterfaceType, + GraphQLList, GraphQLNonNull, GraphQLObjectType, + GraphQLUnionType, is_input_type, is_output_type) class GraphQLTypeMap(OrderedDict): diff --git a/graphql/utils/tests/test_build_ast_schema.py b/graphql/utils/tests/test_build_ast_schema.py index 17032f55..84fad312 100644 --- a/graphql/utils/tests/test_build_ast_schema.py +++ b/graphql/utils/tests/test_build_ast_schema.py @@ -1,9 +1,9 @@ -from pytest import raises - from graphql import GraphQLInt, parse from graphql.utils.build_ast_schema import build_ast_schema from graphql.utils.schema_printer import print_schema +from pytest import raises + from ...type import (GraphQLDeprecatedDirective, GraphQLIncludeDirective, GraphQLSkipDirective) diff --git a/graphql/utils/tests/test_build_client_schema.py b/graphql/utils/tests/test_build_client_schema.py index 6abecb3e..bbb6687e 100644 --- a/graphql/utils/tests/test_build_client_schema.py +++ b/graphql/utils/tests/test_build_client_schema.py @@ -1,7 +1,5 @@ from collections import OrderedDict -from pytest import raises - from graphql import graphql from graphql.error import format_error from graphql.type import (GraphQLArgument, GraphQLBoolean, GraphQLEnumType, @@ -15,6 +13,8 @@ from graphql.utils.build_client_schema import build_client_schema from graphql.utils.introspection_query import introspection_query +from pytest import raises + from ...pyutils.contain_subset import contain_subset diff --git a/graphql/utils/tests/test_extend_schema.py b/graphql/utils/tests/test_extend_schema.py index 194d984d..a3297fd0 100644 --- a/graphql/utils/tests/test_extend_schema.py +++ b/graphql/utils/tests/test_extend_schema.py @@ -1,7 +1,5 @@ from collections import OrderedDict -from pytest import raises - from graphql import parse from graphql.execution import execute from graphql.type import (GraphQLArgument, GraphQLEnumType, GraphQLEnumValue, @@ -11,6 +9,8 @@ from graphql.utils.extend_schema import extend_schema from graphql.utils.schema_printer import print_schema +from pytest import raises + # Test schema. SomeInterfaceType = GraphQLInterfaceType( name='SomeInterface', diff --git a/tox.ini b/tox.ini index 5fd35571..167a6dac 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = flake8,isort,py27,py33,py34,py35,py36,pre-commit,pypy,docs +envlist = flake8,isort,py27,py34,py35,py36,pre-commit,pypy,docs [testenv] deps = @@ -10,7 +10,7 @@ deps = pytest-mock pytest-benchmark commands = - py{27,33,34,py}: py.test graphql tests {posargs} + py{27,34,py}: py.test graphql tests {posargs} py{35,36}: py.test graphql tests tests_py35 {posargs} [testenv:pre-commit] From 6448e343c0a7e5c33227c24f6c54127f5759ea6a Mon Sep 17 00:00:00 2001 From: Daniel Gallagher Date: Fri, 8 Jun 2018 21:14:49 -0700 Subject: [PATCH 5/9] Stop running flake8 and isort as part of tox since they are now run as part of pre-commit --- tox.ini | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/tox.ini b/tox.ini index 167a6dac..be567ba2 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = flake8,isort,py27,py34,py35,py36,pre-commit,pypy,docs +envlist = py27,py34,py35,py36,pre-commit,pypy,docs [testenv] deps = @@ -22,17 +22,6 @@ setenv = commands = pre-commit {posargs:run --all-files} -[testenv:flake8] -deps = flake8 -commands = flake8 - -[testenv:isort] -basepython=python3.5 -deps = - isort==3.9.6 - gevent==1.1rc1 -commands = isort -rc graphql - [testenv:docs] changedir = docs deps = sphinx From f3eabf7c01826832248acbf63f44548437a123aa Mon Sep 17 00:00:00 2001 From: Daniel Gallagher Date: Thu, 5 Jul 2018 22:04:08 -0700 Subject: [PATCH 6/9] Add in missing imports --- graphql/backend/base.py | 3 ++- graphql/language/lexer.py | 4 ++-- graphql/pyutils/compat.py | 1 - graphql/type/definition.py | 14 +++++++------- graphql/type/tests/test_enum_type.py | 2 +- graphql/utils/tests/test_build_ast_schema.py | 2 +- .../rules/overlapping_fields_can_be_merged.py | 4 ++-- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/graphql/backend/base.py b/graphql/backend/base.py index 16dd76b4..36be85bf 100644 --- a/graphql/backend/base.py +++ b/graphql/backend/base.py @@ -1,6 +1,7 @@ from abc import ABCMeta, abstractmethod - +from ..pyutils.cached_property import cached_property import six +from ..language import ast # Necessary for static type checking if False: # flake8: noqa diff --git a/graphql/language/lexer.py b/graphql/language/lexer.py index a60bc6e2..a017dbce 100644 --- a/graphql/language/lexer.py +++ b/graphql/language/lexer.py @@ -372,7 +372,7 @@ def read_string(source, start): position += 1 if code == 92: # \ - append(body[chunk_start : position - 1]) + append(body[chunk_start: position - 1]) code = char_code_at(body, position) escaped = ESCAPED_CHAR_CODES.get(code) # type: ignore @@ -392,7 +392,7 @@ def read_string(source, start): source, position, u"Invalid character escape sequence: \\u{}.".format( - body[position + 1 : position + 5] + body[position + 1: position + 5] ), ) diff --git a/graphql/pyutils/compat.py b/graphql/pyutils/compat.py index 0012f20b..43613d74 100644 --- a/graphql/pyutils/compat.py +++ b/graphql/pyutils/compat.py @@ -240,4 +240,3 @@ def check_threads(): '(Enable the "enable-threads" flag).' ) ) - diff --git a/graphql/type/definition.py b/graphql/type/definition.py index 9099242e..ce9dffb5 100644 --- a/graphql/type/definition.py +++ b/graphql/type/definition.py @@ -626,17 +626,17 @@ class GeoPoint(GraphQLInputObjectType): """ def __init__(self, - name, # type: str - fields, # type: Union[Callable[[], Dict[str, GraphQLInputObjectField]], Dict[str, GraphQLInputObjectField]] - description=None, # type: Optional[str] - container_type=None, # type: Type[Dict[str, Any]] - ): + name, # type: str + fields, # type: Union[Callable[[], Dict[str, GraphQLInputObjectField]], Dict[str, GraphQLInputObjectField]] + description=None, # type: Optional[str] + container_type=None, # type: Type[Dict[str, Any]] + ): # type: (...) -> None assert name, "Type must be named." self.name = name self.description = description if container_type is None: - container_type = dict # type: ignore + container_type = dict # type: ignore assert callable(container_type), "container_type must be callable" self.container_type = container_type self._fields = fields @@ -755,7 +755,7 @@ class RowType(GraphQLObjectType): def __init__( self, - type, # type: Union[GraphQLList, GraphQLObjectType, GraphQLScalarType, GraphQLInputObjectType, GraphQLInterfaceType] + type, # type: Union[GraphQLList, GraphQLObjectType, GraphQLScalarType, GraphQLInputObjectType, GraphQLInterfaceType] ): # type: (...) -> None assert is_type(type) and not isinstance( diff --git a/graphql/type/tests/test_enum_type.py b/graphql/type/tests/test_enum_type.py index 6779db9c..989fac82 100644 --- a/graphql/type/tests/test_enum_type.py +++ b/graphql/type/tests/test_enum_type.py @@ -1,5 +1,5 @@ from collections import OrderedDict - +from rx import Observable from graphql import graphql from graphql.type import ( GraphQLArgument, diff --git a/graphql/utils/tests/test_build_ast_schema.py b/graphql/utils/tests/test_build_ast_schema.py index 2080331c..9ac12c2f 100644 --- a/graphql/utils/tests/test_build_ast_schema.py +++ b/graphql/utils/tests/test_build_ast_schema.py @@ -1,7 +1,7 @@ from graphql import GraphQLInt, parse from graphql.utils.build_ast_schema import build_ast_schema from graphql.utils.schema_printer import print_schema - +from pytest import raises from ...type import ( GraphQLDeprecatedDirective, GraphQLIncludeDirective, diff --git a/graphql/validation/rules/overlapping_fields_can_be_merged.py b/graphql/validation/rules/overlapping_fields_can_be_merged.py index 8506e2cd..4cba7ca2 100644 --- a/graphql/validation/rules/overlapping_fields_can_be_merged.py +++ b/graphql/validation/rules/overlapping_fields_can_be_merged.py @@ -207,7 +207,7 @@ def _find_conflicts_within_selection_set( # selection set to collect conflicts within fragments spread together. # This compares each item in the list of fragment names to every other item # in that same list (except for itself). - for other_fragment_name in fragment_names[i + 1 :]: + for other_fragment_name in fragment_names[i + 1:]: _collect_conflicts_between_fragments( context, conflicts, @@ -444,7 +444,7 @@ def _collect_conflicts_within( # (except to itself). If the list only has one item, nothing needs to # be compared. for i, field in enumerate(fields): - for other_field in fields[i + 1 :]: + for other_field in fields[i + 1:]: # within one collection is never mutually exclusive conflict = _find_conflict( context, From 077ea2bd65bd7426b86c670990918f630de42cce Mon Sep 17 00:00:00 2001 From: Daniel Gallagher Date: Thu, 5 Jul 2018 22:19:40 -0700 Subject: [PATCH 7/9] Minimize unnecesary diff --- .travis.yml | 2 + graphql/backend/base.py | 6 +- graphql/backend/cache.py | 2 +- graphql/backend/compiled.py | 1 - graphql/backend/core.py | 6 +- graphql/backend/quiver_cloud.py | 2 +- graphql/backend/tests/test_base.py | 3 +- graphql/backend/tests/test_cache.py | 5 +- graphql/backend/tests/test_core.py | 3 +- graphql/backend/tests/test_decider.py | 3 +- graphql/error/base.py | 1 - graphql/error/tests/test_base.py | 3 +- graphql/execution/executor.py | 4 +- graphql/execution/executors/asyncio_utils.py | 103 +------------------ graphql/execution/tests/test_executor.py | 4 +- tox.ini | 9 +- 16 files changed, 33 insertions(+), 124 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4772256d..18723a45 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,8 @@ matrix: python: pypy-5.7.1 - env: TOXENV=pre-commit python: 3.6 + - env: TOXENV=mypy + python: 3.6 install: pip install coveralls tox script: tox after_success: coveralls diff --git a/graphql/backend/base.py b/graphql/backend/base.py index 36be85bf..6573d3a7 100644 --- a/graphql/backend/base.py +++ b/graphql/backend/base.py @@ -1,8 +1,10 @@ -from abc import ABCMeta, abstractmethod from ..pyutils.cached_property import cached_property -import six from ..language import ast +from abc import ABCMeta, abstractmethod +import six + + # Necessary for static type checking if False: # flake8: noqa from typing import Dict, Optional, Union, Callable diff --git a/graphql/backend/cache.py b/graphql/backend/cache.py index 08edfc98..00680644 100644 --- a/graphql/backend/cache.py +++ b/graphql/backend/cache.py @@ -1,8 +1,8 @@ from hashlib import sha1 from six import string_types - from ..type import GraphQLSchema + from .base import GraphQLBackend # Necessary for static type checking diff --git a/graphql/backend/compiled.py b/graphql/backend/compiled.py index d62c6d39..e3805cd1 100644 --- a/graphql/backend/compiled.py +++ b/graphql/backend/compiled.py @@ -1,5 +1,4 @@ from six import string_types - from .base import GraphQLDocument # Necessary for static type checking diff --git a/graphql/backend/core.py b/graphql/backend/core.py index ab1e8a88..0dc88dad 100644 --- a/graphql/backend/core.py +++ b/graphql/backend/core.py @@ -1,11 +1,11 @@ from functools import partial - from six import string_types -from ..execution import ExecutionResult, execute -from ..language import ast +from ..execution import execute, ExecutionResult from ..language.base import parse, print_ast +from ..language import ast from ..validation import validate + from .base import GraphQLBackend, GraphQLDocument # Necessary for static type checking diff --git a/graphql/backend/quiver_cloud.py b/graphql/backend/quiver_cloud.py index de631e5b..280f23d9 100644 --- a/graphql/backend/quiver_cloud.py +++ b/graphql/backend/quiver_cloud.py @@ -7,12 +7,12 @@ ) from ..utils.schema_printer import print_schema + from .base import GraphQLBackend from .compiled import GraphQLCompiledDocument from six.moves.urllib.parse import urlparse - GRAPHQL_QUERY = """ mutation($schemaDsl: String!, $query: String!, $pythonOptions: PythonOptions) { generateCode( diff --git a/graphql/backend/tests/test_base.py b/graphql/backend/tests/test_base.py index f068d6bd..c9a8dfda 100644 --- a/graphql/backend/tests/test_base.py +++ b/graphql/backend/tests/test_base.py @@ -1,6 +1,5 @@ import pytest - -from .. import GraphQLCoreBackend, get_default_backend, set_default_backend +from .. import get_default_backend, set_default_backend, GraphQLCoreBackend def test_get_default_backend_returns_core_by_default(): diff --git a/graphql/backend/tests/test_cache.py b/graphql/backend/tests/test_cache.py index c95bddb2..a20a18c1 100644 --- a/graphql/backend/tests/test_cache.py +++ b/graphql/backend/tests/test_cache.py @@ -2,12 +2,11 @@ # -*- coding: utf-8 -*- """Tests for `graphql.backend.cache` module.""" -from graphql.execution.executors.sync import SyncExecutor - import pytest -from ..cache import GraphQLCachedBackend from ..core import GraphQLCoreBackend +from ..cache import GraphQLCachedBackend +from graphql.execution.executors.sync import SyncExecutor from .schema import schema diff --git a/graphql/backend/tests/test_core.py b/graphql/backend/tests/test_core.py index a9db2792..257eb64b 100644 --- a/graphql/backend/tests/test_core.py +++ b/graphql/backend/tests/test_core.py @@ -2,9 +2,8 @@ # -*- coding: utf-8 -*- """Tests for `graphql.backend.core` module.""" -from graphql.execution.executors.sync import SyncExecutor - import pytest +from graphql.execution.executors.sync import SyncExecutor from ..base import GraphQLBackend, GraphQLDocument from ..core import GraphQLCoreBackend diff --git a/graphql/backend/tests/test_decider.py b/graphql/backend/tests/test_decider.py index 121061fe..32dccaee 100644 --- a/graphql/backend/tests/test_decider.py +++ b/graphql/backend/tests/test_decider.py @@ -6,9 +6,10 @@ from threading import Event from ..base import GraphQLBackend, GraphQLDocument -from ..cache import GraphQLCachedBackend from ..core import GraphQLCoreBackend +from ..cache import GraphQLCachedBackend from ..decider import GraphQLDeciderBackend + from .schema import schema if False: diff --git a/graphql/error/base.py b/graphql/error/base.py index a26eaca5..c57d0959 100644 --- a/graphql/error/base.py +++ b/graphql/error/base.py @@ -1,5 +1,4 @@ import six - from ..language.location import get_location # Necessary for static type checking diff --git a/graphql/error/tests/test_base.py b/graphql/error/tests/test_base.py index 9c1c5d58..e53f152a 100644 --- a/graphql/error/tests/test_base.py +++ b/graphql/error/tests/test_base.py @@ -1,3 +1,4 @@ +import pytest import traceback from graphql.execution import execute @@ -10,8 +11,6 @@ from typing import Any from typing import Optional -import pytest - def test_raise(): # type: () -> None diff --git a/graphql/execution/executor.py b/graphql/execution/executor.py index baf9e42b..7e49fdf8 100644 --- a/graphql/execution/executor.py +++ b/graphql/execution/executor.py @@ -3,10 +3,10 @@ import logging import sys import warnings - -from promise import Promise, is_thenable, promise_for_dict from rx import Observable + from six import string_types +from promise import Promise, promise_for_dict, is_thenable from ..error import GraphQLError, GraphQLLocatedError from ..pyutils.default_ordered_dict import DefaultOrderedDict diff --git a/graphql/execution/executors/asyncio_utils.py b/graphql/execution/executors/asyncio_utils.py index 51030895..17ec5c79 100644 --- a/graphql/execution/executors/asyncio_utils.py +++ b/graphql/execution/executors/asyncio_utils.py @@ -1,108 +1,11 @@ from inspect import isasyncgen # type: ignore from asyncio import ensure_future, wait, CancelledError -from inspect import isasyncgen - -from rx import AnonymousObserver, Observable -from rx.concurrency import current_thread_scheduler -from rx.core import (Disposable, Observable, ObservableBase, Observer, - ObserverBase) -from rx.core.anonymousobserver import AnonymousObserver -from rx.core.autodetachobserver import AutoDetachObserver from rx import AnonymousObservable -# class AsyncgenDisposable(Disposable): -# """Represents a Disposable that disposes the asyncgen automatically.""" - -# def __init__(self, asyncgen): -# """Initializes a new instance of the AsyncgenDisposable class.""" - -# self.asyncgen = asyncgen -# self.is_disposed = False - -# super(AsyncgenDisposable, self).__init__() - -# def dispose(self): -# """Sets the status to disposed""" -# self.asyncgen.aclose() -# self.is_disposed = True - - -class AsyncgenObserver(AutoDetachObserver): - def __init__(self, asyncgen, *args, **kwargs): - self._asyncgen = asyncgen - self.is_disposed = False - super(AsyncgenObserver, self).__init__(*args, **kwargs) - - async def dispose_asyncgen(self): - if self.is_disposed: - return - - try: - # await self._asyncgen.aclose() - await self._asyncgen.athrow(StopAsyncIteration) - self.is_disposed = True - except: - pass - - def dispose(self): - if self.is_disposed: - return - disposed = super(AsyncgenObserver, self).dispose() - # print("DISPOSE observer!", disposed) - ensure_future(self.dispose_asyncgen()) - - -class AsyncgenObservable(ObservableBase): - """Class to create an Observable instance from a delegate-based - implementation of the Subscribe method.""" - - def __init__(self, subscribe, asyncgen): - """Creates an observable sequence object from the specified - subscription function. - - Keyword arguments: - :param types.FunctionType subscribe: Subscribe method implementation. - """ - - self._subscribe = subscribe - self._asyncgen = asyncgen - super(AsyncgenObservable, self).__init__() - - def _subscribe_core(self, observer): - # print("GET SUBSCRIBER", observer) - return self._subscribe(observer) - # print("SUBSCRIBER RESULT", subscriber) - # return subscriber - - def subscribe(self, on_next=None, on_error=None, on_completed=None, observer=None): - - if isinstance(on_next, Observer): - observer = on_next - elif hasattr(on_next, "on_next") and callable(on_next.on_next): - observer = on_next - elif not observer: - observer = AnonymousObserver(on_next, on_error, on_completed) - - auto_detach_observer = AsyncgenObserver(self._asyncgen, observer) - - def fix_subscriber(subscriber): - """Fixes subscriber to make sure it returns a Disposable instead - of None or a dispose function""" - - if not hasattr(subscriber, "dispose"): - subscriber = Disposable.create(subscriber) - - return subscriber - - def set_disposable(scheduler=None, value=None): - try: - subscriber = self._subscribe_core(auto_detach_observer) - except Exception as ex: - if not auto_detach_observer.fail(ex): - raise - else: - auto_detach_observer.disposable = fix_subscriber(subscriber) +def asyncgen_to_observable(asyncgen, loop=None): + def emit(observer): + task = ensure_future(iterate_asyncgen(asyncgen, observer), loop=loop) def dispose(): async def await_task(): diff --git a/graphql/execution/tests/test_executor.py b/graphql/execution/tests/test_executor.py index 360bd37e..88e5b693 100644 --- a/graphql/execution/tests/test_executor.py +++ b/graphql/execution/tests/test_executor.py @@ -1,6 +1,8 @@ # type: ignore import json +from pytest import raises + from graphql.error import GraphQLError from graphql.execution import MiddlewareManager, execute from graphql.language.parser import parse @@ -18,8 +20,6 @@ ) from promise import Promise -from pytest import raises - def test_executes_arbitary_code(): # type: () -> None diff --git a/tox.ini b/tox.ini index be567ba2..fb860075 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py27,py34,py35,py36,pre-commit,pypy,docs +envlist = py27,py34,py35,py36,pre-commit,pypy,mypy,docs [testenv] deps = @@ -22,6 +22,13 @@ setenv = commands = pre-commit {posargs:run --all-files} +[testenv:mypy] +basepython=python3.6 +deps = + mypy +commands = + mypy graphql --ignore-missing-imports + [testenv:docs] changedir = docs deps = sphinx From bc7ec5862b92e07fcaff23454e7aed08ea41f515 Mon Sep 17 00:00:00 2001 From: Daniel Gallagher Date: Thu, 5 Jul 2018 22:28:09 -0700 Subject: [PATCH 8/9] Minimize diff further --- graphql/execution/tests/test_subscribe.py | 4 ---- graphql/execution/tests/test_variables.py | 3 +-- graphql/graphql.py | 5 ++--- graphql/language/tests/test_lexer.py | 4 ++-- graphql/language/tests/test_parser.py | 4 ++-- graphql/language/tests/test_printer.py | 4 ++-- graphql/language/tests/test_schema_parser.py | 4 ++-- graphql/language/tests/test_schema_printer.py | 2 ++ graphql/pyutils/tests/test_default_ordered_dict.py | 4 ++-- graphql/type/tests/test_serialization.py | 2 -- graphql/type/tests/test_validation.py | 2 -- graphql/utils/tests/test_build_ast_schema.py | 4 +++- graphql/utils/tests/test_build_client_schema.py | 4 ++-- graphql/utils/tests/test_extend_schema.py | 4 ++-- 14 files changed, 22 insertions(+), 28 deletions(-) diff --git a/graphql/execution/tests/test_subscribe.py b/graphql/execution/tests/test_subscribe.py index 58ea6a7d..2fa039c3 100644 --- a/graphql/execution/tests/test_subscribe.py +++ b/graphql/execution/tests/test_subscribe.py @@ -1,9 +1,5 @@ # type: ignore from collections import OrderedDict, namedtuple - -from graphql import (GraphQLBoolean, GraphQLField, GraphQLInt, GraphQLList, - GraphQLObjectType, GraphQLSchema, GraphQLString, graphql, - parse, subscribe) from rx import Observable, Observer from rx.subjects import Subject from graphql import ( diff --git a/graphql/execution/tests/test_variables.py b/graphql/execution/tests/test_variables.py index fe336258..a4a1a8fe 100644 --- a/graphql/execution/tests/test_variables.py +++ b/graphql/execution/tests/test_variables.py @@ -2,6 +2,7 @@ import json from collections import OrderedDict +from pytest import raises from graphql.error import GraphQLError, format_error from graphql.execution import execute from graphql.language.parser import parse @@ -25,8 +26,6 @@ # from typing import Dict # from typing import Union -from pytest import raises - TestComplexScalar = GraphQLScalarType( name="ComplexScalar", serialize=lambda v: "SerializedValue" if v == "DeserializedValue" else None, diff --git a/graphql/graphql.py b/graphql/graphql.py index 3c254138..89ccf386 100644 --- a/graphql/graphql.py +++ b/graphql/graphql.py @@ -1,8 +1,7 @@ -from promise import promisify - -from .backend import get_default_backend from .execution import ExecutionResult +from .backend import get_default_backend +from promise import promisify # Necessary for static type checking if False: # flake8: noqa diff --git a/graphql/language/tests/test_lexer.py b/graphql/language/tests/test_lexer.py index 552d88d9..dda777d9 100644 --- a/graphql/language/tests/test_lexer.py +++ b/graphql/language/tests/test_lexer.py @@ -1,9 +1,9 @@ +from pytest import raises + from graphql.error import GraphQLSyntaxError from graphql.language.lexer import Lexer, Token, TokenKind from graphql.language.source import Source -from pytest import raises - def lex_one(s): # type: (str) -> Token diff --git a/graphql/language/tests/test_parser.py b/graphql/language/tests/test_parser.py index 2d72b70f..6c9d5f47 100644 --- a/graphql/language/tests/test_parser.py +++ b/graphql/language/tests/test_parser.py @@ -1,11 +1,11 @@ +from pytest import raises + from graphql.error import GraphQLSyntaxError from graphql.language import ast from graphql.language.location import SourceLocation from graphql.language.parser import Loc, parse from graphql.language.source import Source -from pytest import raises - from .fixtures import KITCHEN_SINK diff --git a/graphql/language/tests/test_printer.py b/graphql/language/tests/test_printer.py index ef002150..470991df 100644 --- a/graphql/language/tests/test_printer.py +++ b/graphql/language/tests/test_printer.py @@ -1,11 +1,11 @@ import copy +from pytest import raises + from graphql.language.ast import Field, Name from graphql.language.parser import parse from graphql.language.printer import print_ast -from pytest import raises - from .fixtures import KITCHEN_SINK diff --git a/graphql/language/tests/test_schema_parser.py b/graphql/language/tests/test_schema_parser.py index 35bd41bd..6ec58d4d 100644 --- a/graphql/language/tests/test_schema_parser.py +++ b/graphql/language/tests/test_schema_parser.py @@ -1,11 +1,11 @@ +from pytest import raises + from graphql import Source, parse from graphql.error import GraphQLSyntaxError from graphql.language import ast from graphql.language.parser import Loc from typing import Callable -from pytest import raises - def create_loc_fn(body): # type: (str) -> Callable diff --git a/graphql/language/tests/test_schema_printer.py b/graphql/language/tests/test_schema_printer.py index 736c73ff..c7272e7f 100644 --- a/graphql/language/tests/test_schema_printer.py +++ b/graphql/language/tests/test_schema_printer.py @@ -1,5 +1,7 @@ from copy import deepcopy +from pytest import raises + from graphql import parse from graphql.language import ast from graphql.language.printer import print_ast diff --git a/graphql/pyutils/tests/test_default_ordered_dict.py b/graphql/pyutils/tests/test_default_ordered_dict.py index dd256dfe..0a87a8dd 100644 --- a/graphql/pyutils/tests/test_default_ordered_dict.py +++ b/graphql/pyutils/tests/test_default_ordered_dict.py @@ -1,10 +1,10 @@ import copy import pickle -from graphql.pyutils.default_ordered_dict import DefaultOrderedDict - from pytest import raises +from graphql.pyutils.default_ordered_dict import DefaultOrderedDict + def test_will_missing_will_set_value_from_factory(): d = DefaultOrderedDict(list) diff --git a/graphql/type/tests/test_serialization.py b/graphql/type/tests/test_serialization.py index 06afc855..3cb09338 100644 --- a/graphql/type/tests/test_serialization.py +++ b/graphql/type/tests/test_serialization.py @@ -2,8 +2,6 @@ from graphql.type import GraphQLBoolean, GraphQLFloat, GraphQLInt, GraphQLString -import pytest - def test_serializes_output_int(): assert GraphQLInt.serialize(1) == 1 diff --git a/graphql/type/tests/test_validation.py b/graphql/type/tests/test_validation.py index 03a33653..4bead700 100644 --- a/graphql/type/tests/test_validation.py +++ b/graphql/type/tests/test_validation.py @@ -19,8 +19,6 @@ ) from graphql.type.definition import GraphQLArgument -from pytest import raises - _none = lambda *args: None _true = lambda *args: True _false = lambda *args: False diff --git a/graphql/utils/tests/test_build_ast_schema.py b/graphql/utils/tests/test_build_ast_schema.py index 9ac12c2f..6f84aa64 100644 --- a/graphql/utils/tests/test_build_ast_schema.py +++ b/graphql/utils/tests/test_build_ast_schema.py @@ -1,7 +1,9 @@ +from pytest import raises + from graphql import GraphQLInt, parse from graphql.utils.build_ast_schema import build_ast_schema from graphql.utils.schema_printer import print_schema -from pytest import raises + from ...type import ( GraphQLDeprecatedDirective, GraphQLIncludeDirective, diff --git a/graphql/utils/tests/test_build_client_schema.py b/graphql/utils/tests/test_build_client_schema.py index ff7d3eea..5e2f496a 100644 --- a/graphql/utils/tests/test_build_client_schema.py +++ b/graphql/utils/tests/test_build_client_schema.py @@ -1,5 +1,7 @@ from collections import OrderedDict +from pytest import raises + from graphql import graphql from graphql.error import format_error from graphql.type import ( @@ -26,8 +28,6 @@ from graphql.utils.build_client_schema import build_client_schema from graphql.utils.introspection_query import introspection_query -from pytest import raises - from ...pyutils.contain_subset import contain_subset diff --git a/graphql/utils/tests/test_extend_schema.py b/graphql/utils/tests/test_extend_schema.py index 5ea257d5..ac1c882d 100644 --- a/graphql/utils/tests/test_extend_schema.py +++ b/graphql/utils/tests/test_extend_schema.py @@ -1,5 +1,7 @@ from collections import OrderedDict +from pytest import raises + from graphql import parse from graphql.execution import execute from graphql.type import ( @@ -19,8 +21,6 @@ from graphql.utils.extend_schema import extend_schema from graphql.utils.schema_printer import print_schema -from pytest import raises - # Test schema. SomeInterfaceType = GraphQLInterfaceType( name="SomeInterface", From c663913e7f6ffa4ea47d8a45914612502e7f9597 Mon Sep 17 00:00:00 2001 From: Daniel Gallagher Date: Thu, 5 Jul 2018 22:29:16 -0700 Subject: [PATCH 9/9] Minimize diff further --- graphql/language/tests/test_schema_printer.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/graphql/language/tests/test_schema_printer.py b/graphql/language/tests/test_schema_printer.py index c7272e7f..afa979cb 100644 --- a/graphql/language/tests/test_schema_printer.py +++ b/graphql/language/tests/test_schema_printer.py @@ -6,8 +6,6 @@ from graphql.language import ast from graphql.language.printer import print_ast -from pytest import raises - from .fixtures import SCHEMA_KITCHEN_SINK