Skip to content

Commit 077ea2b

Browse files
author
Daniel Gallagher
committed
Minimize unnecesary diff
1 parent f3eabf7 commit 077ea2b

File tree

16 files changed

+33
-124
lines changed

16 files changed

+33
-124
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ matrix:
1212
python: pypy-5.7.1
1313
- env: TOXENV=pre-commit
1414
python: 3.6
15+
- env: TOXENV=mypy
16+
python: 3.6
1517
install: pip install coveralls tox
1618
script: tox
1719
after_success: coveralls

graphql/backend/base.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
from abc import ABCMeta, abstractmethod
21
from ..pyutils.cached_property import cached_property
3-
import six
42
from ..language import ast
53

4+
from abc import ABCMeta, abstractmethod
5+
import six
6+
7+
68
# Necessary for static type checking
79
if False: # flake8: noqa
810
from typing import Dict, Optional, Union, Callable

graphql/backend/cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from hashlib import sha1
22

33
from six import string_types
4-
54
from ..type import GraphQLSchema
5+
66
from .base import GraphQLBackend
77

88
# Necessary for static type checking

graphql/backend/compiled.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from six import string_types
2-
32
from .base import GraphQLDocument
43

54
# Necessary for static type checking

graphql/backend/core.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from functools import partial
2-
32
from six import string_types
43

5-
from ..execution import ExecutionResult, execute
6-
from ..language import ast
4+
from ..execution import execute, ExecutionResult
75
from ..language.base import parse, print_ast
6+
from ..language import ast
87
from ..validation import validate
8+
99
from .base import GraphQLBackend, GraphQLDocument
1010

1111
# Necessary for static type checking

graphql/backend/quiver_cloud.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
)
88

99
from ..utils.schema_printer import print_schema
10+
1011
from .base import GraphQLBackend
1112
from .compiled import GraphQLCompiledDocument
1213

1314
from six.moves.urllib.parse import urlparse
1415

15-
1616
GRAPHQL_QUERY = """
1717
mutation($schemaDsl: String!, $query: String!, $pythonOptions: PythonOptions) {
1818
generateCode(

graphql/backend/tests/test_base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import pytest
2-
3-
from .. import GraphQLCoreBackend, get_default_backend, set_default_backend
2+
from .. import get_default_backend, set_default_backend, GraphQLCoreBackend
43

54

65
def test_get_default_backend_returns_core_by_default():

graphql/backend/tests/test_cache.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
# -*- coding: utf-8 -*-
33
"""Tests for `graphql.backend.cache` module."""
44

5-
from graphql.execution.executors.sync import SyncExecutor
6-
75
import pytest
86

9-
from ..cache import GraphQLCachedBackend
107
from ..core import GraphQLCoreBackend
8+
from ..cache import GraphQLCachedBackend
9+
from graphql.execution.executors.sync import SyncExecutor
1110
from .schema import schema
1211

1312

graphql/backend/tests/test_core.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
# -*- coding: utf-8 -*-
33
"""Tests for `graphql.backend.core` module."""
44

5-
from graphql.execution.executors.sync import SyncExecutor
6-
75
import pytest
6+
from graphql.execution.executors.sync import SyncExecutor
87

98
from ..base import GraphQLBackend, GraphQLDocument
109
from ..core import GraphQLCoreBackend

graphql/backend/tests/test_decider.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
from threading import Event
77

88
from ..base import GraphQLBackend, GraphQLDocument
9-
from ..cache import GraphQLCachedBackend
109
from ..core import GraphQLCoreBackend
10+
from ..cache import GraphQLCachedBackend
1111
from ..decider import GraphQLDeciderBackend
12+
1213
from .schema import schema
1314

1415
if False:

graphql/error/base.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import six
2-
32
from ..language.location import get_location
43

54
# Necessary for static type checking

graphql/error/tests/test_base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import pytest
12
import traceback
23

34
from graphql.execution import execute
@@ -10,8 +11,6 @@
1011
from typing import Any
1112
from typing import Optional
1213

13-
import pytest
14-
1514

1615
def test_raise():
1716
# type: () -> None

graphql/execution/executor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import logging
44
import sys
55
import warnings
6-
7-
from promise import Promise, is_thenable, promise_for_dict
86
from rx import Observable
7+
98
from six import string_types
9+
from promise import Promise, promise_for_dict, is_thenable
1010

1111
from ..error import GraphQLError, GraphQLLocatedError
1212
from ..pyutils.default_ordered_dict import DefaultOrderedDict

graphql/execution/executors/asyncio_utils.py

Lines changed: 3 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,11 @@
11
from inspect import isasyncgen # type: ignore
22
from asyncio import ensure_future, wait, CancelledError
3-
from inspect import isasyncgen
4-
5-
from rx import AnonymousObserver, Observable
6-
from rx.concurrency import current_thread_scheduler
7-
from rx.core import (Disposable, Observable, ObservableBase, Observer,
8-
ObserverBase)
9-
from rx.core.anonymousobserver import AnonymousObserver
10-
from rx.core.autodetachobserver import AutoDetachObserver
113
from rx import AnonymousObservable
124

135

14-
# class AsyncgenDisposable(Disposable):
15-
# """Represents a Disposable that disposes the asyncgen automatically."""
16-
17-
# def __init__(self, asyncgen):
18-
# """Initializes a new instance of the AsyncgenDisposable class."""
19-
20-
# self.asyncgen = asyncgen
21-
# self.is_disposed = False
22-
23-
# super(AsyncgenDisposable, self).__init__()
24-
25-
# def dispose(self):
26-
# """Sets the status to disposed"""
27-
# self.asyncgen.aclose()
28-
# self.is_disposed = True
29-
30-
31-
class AsyncgenObserver(AutoDetachObserver):
32-
def __init__(self, asyncgen, *args, **kwargs):
33-
self._asyncgen = asyncgen
34-
self.is_disposed = False
35-
super(AsyncgenObserver, self).__init__(*args, **kwargs)
36-
37-
async def dispose_asyncgen(self):
38-
if self.is_disposed:
39-
return
40-
41-
try:
42-
# await self._asyncgen.aclose()
43-
await self._asyncgen.athrow(StopAsyncIteration)
44-
self.is_disposed = True
45-
except:
46-
pass
47-
48-
def dispose(self):
49-
if self.is_disposed:
50-
return
51-
disposed = super(AsyncgenObserver, self).dispose()
52-
# print("DISPOSE observer!", disposed)
53-
ensure_future(self.dispose_asyncgen())
54-
55-
56-
class AsyncgenObservable(ObservableBase):
57-
"""Class to create an Observable instance from a delegate-based
58-
implementation of the Subscribe method."""
59-
60-
def __init__(self, subscribe, asyncgen):
61-
"""Creates an observable sequence object from the specified
62-
subscription function.
63-
64-
Keyword arguments:
65-
:param types.FunctionType subscribe: Subscribe method implementation.
66-
"""
67-
68-
self._subscribe = subscribe
69-
self._asyncgen = asyncgen
70-
super(AsyncgenObservable, self).__init__()
71-
72-
def _subscribe_core(self, observer):
73-
# print("GET SUBSCRIBER", observer)
74-
return self._subscribe(observer)
75-
# print("SUBSCRIBER RESULT", subscriber)
76-
# return subscriber
77-
78-
def subscribe(self, on_next=None, on_error=None, on_completed=None, observer=None):
79-
80-
if isinstance(on_next, Observer):
81-
observer = on_next
82-
elif hasattr(on_next, "on_next") and callable(on_next.on_next):
83-
observer = on_next
84-
elif not observer:
85-
observer = AnonymousObserver(on_next, on_error, on_completed)
86-
87-
auto_detach_observer = AsyncgenObserver(self._asyncgen, observer)
88-
89-
def fix_subscriber(subscriber):
90-
"""Fixes subscriber to make sure it returns a Disposable instead
91-
of None or a dispose function"""
92-
93-
if not hasattr(subscriber, "dispose"):
94-
subscriber = Disposable.create(subscriber)
95-
96-
return subscriber
97-
98-
def set_disposable(scheduler=None, value=None):
99-
try:
100-
subscriber = self._subscribe_core(auto_detach_observer)
101-
except Exception as ex:
102-
if not auto_detach_observer.fail(ex):
103-
raise
104-
else:
105-
auto_detach_observer.disposable = fix_subscriber(subscriber)
6+
def asyncgen_to_observable(asyncgen, loop=None):
7+
def emit(observer):
8+
task = ensure_future(iterate_asyncgen(asyncgen, observer), loop=loop)
1069

10710
def dispose():
10811
async def await_task():

graphql/execution/tests/test_executor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# type: ignore
22
import json
33

4+
from pytest import raises
5+
46
from graphql.error import GraphQLError
57
from graphql.execution import MiddlewareManager, execute
68
from graphql.language.parser import parse
@@ -18,8 +20,6 @@
1820
)
1921
from promise import Promise
2022

21-
from pytest import raises
22-
2323

2424
def test_executes_arbitary_code():
2525
# type: () -> None

tox.ini

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = py27,py34,py35,py36,pre-commit,pypy,docs
2+
envlist = py27,py34,py35,py36,pre-commit,pypy,mypy,docs
33

44
[testenv]
55
deps =
@@ -22,6 +22,13 @@ setenv =
2222
commands =
2323
pre-commit {posargs:run --all-files}
2424

25+
[testenv:mypy]
26+
basepython=python3.6
27+
deps =
28+
mypy
29+
commands =
30+
mypy graphql --ignore-missing-imports
31+
2532
[testenv:docs]
2633
changedir = docs
2734
deps = sphinx

0 commit comments

Comments
 (0)