Skip to content

Commit 7e45815

Browse files
authored
Support python 3.10 (#264)
Add Python 3.10 tests on tox and on GitHub actions Update websockets to 10 for Python versions >= 3.6 Update pytest related dependencies Update mypy dependency + add new required types dependencies Ignore new "There is no current event loop" warnings
1 parent eb986df commit 7e45815

File tree

8 files changed

+59
-20
lines changed

8 files changed

+59
-20
lines changed

.github/workflows/tests.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
strategy:
99
max-parallel: 4
1010
matrix:
11-
python-version: ["3.6", "3.7", "3.8", "3.9", "pypy3"]
11+
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "pypy3"]
1212
os: [ubuntu-latest, windows-latest]
1313
exclude:
1414
- os: windows-latest
@@ -17,6 +17,8 @@ jobs:
1717
python-version: "3.7"
1818
- os: windows-latest
1919
python-version: "3.9"
20+
- os: windows-latest
21+
python-version: "3.10"
2022
- os: windows-latest
2123
python-version: "pypy3"
2224

gql/client.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
import warnings
23
from typing import Any, AsyncGenerator, Dict, Generator, Optional, Union
34

45
from graphql import (
@@ -151,7 +152,11 @@ def execute(self, document: DocumentNode, *args, **kwargs) -> Dict:
151152
# Get the current asyncio event loop
152153
# Or create a new event loop if there isn't one (in a new Thread)
153154
try:
154-
loop = asyncio.get_event_loop()
155+
with warnings.catch_warnings():
156+
warnings.filterwarnings(
157+
"ignore", message="There is no current event loop"
158+
)
159+
loop = asyncio.get_event_loop()
155160
except RuntimeError:
156161
loop = asyncio.new_event_loop()
157162
asyncio.set_event_loop(loop)
@@ -194,7 +199,11 @@ def subscribe(
194199
# Get the current asyncio event loop
195200
# Or create a new event loop if there isn't one (in a new Thread)
196201
try:
197-
loop = asyncio.get_event_loop()
202+
with warnings.catch_warnings():
203+
warnings.filterwarnings(
204+
"ignore", message="There is no current event loop"
205+
)
206+
loop = asyncio.get_event_loop()
198207
except RuntimeError:
199208
loop = asyncio.new_event_loop()
200209
asyncio.set_event_loop(loop)
@@ -211,7 +220,11 @@ def subscribe(
211220
# Note: we need to create a task here in order to be able to close
212221
# the async generator properly on python 3.8
213222
# See https://bugs.python.org/issue38559
214-
generator_task = asyncio.ensure_future(async_generator.__anext__())
223+
with warnings.catch_warnings():
224+
warnings.filterwarnings(
225+
"ignore", message="There is no current event loop"
226+
)
227+
generator_task = asyncio.ensure_future(async_generator.__anext__())
215228
result = loop.run_until_complete(generator_task)
216229
yield result
217230

gql/transport/websockets.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import asyncio
22
import json
33
import logging
4+
import warnings
45
from contextlib import suppress
56
from ssl import SSLContext
67
from typing import Any, AsyncGenerator, Dict, Optional, Tuple, Union, cast
@@ -165,7 +166,11 @@ def __init__(
165166
# We need to set an event loop here if there is none
166167
# Or else we will not be able to create an asyncio.Event()
167168
try:
168-
self._loop = asyncio.get_event_loop()
169+
with warnings.catch_warnings():
170+
warnings.filterwarnings(
171+
"ignore", message="There is no current event loop"
172+
)
173+
self._loop = asyncio.get_event_loop()
169174
except RuntimeError:
170175
self._loop = asyncio.new_event_loop()
171176
asyncio.set_event_loop(self._loop)

setup.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
tests_requires = [
1515
"parse==1.15.0",
16-
"pytest==5.4.2",
17-
"pytest-asyncio==0.11.0",
18-
"pytest-cov==2.8.1",
16+
"pytest==6.2.5",
17+
"pytest-asyncio==0.16.0",
18+
"pytest-cov==3.0.0",
1919
"mock==4.0.2",
2020
"vcrpy==4.0.2",
2121
"aiofiles",
@@ -26,10 +26,13 @@
2626
"check-manifest>=0.42,<1",
2727
"flake8==3.8.1",
2828
"isort==4.3.21",
29-
"mypy==0.770",
29+
"mypy==0.910",
3030
"sphinx>=3.0.0,<4",
3131
"sphinx_rtd_theme>=0.4,<1",
3232
"sphinx-argparse==0.2.5",
33+
"types-aiofiles",
34+
"types-mock",
35+
"types-requests",
3336
] + tests_requires
3437

3538
install_aiohttp_requires = [
@@ -43,7 +46,8 @@
4346
]
4447

4548
install_websockets_requires = [
46-
"websockets>=9,<10",
49+
"websockets>=9,<10;python_version<='3.6'",
50+
"websockets>=10,<11;python_version>'3.6'",
4751
]
4852

4953
install_all_requires = (
@@ -67,14 +71,16 @@
6771
author_email="[email protected]",
6872
license="MIT",
6973
classifiers=[
70-
"Development Status :: 3 - Alpha",
74+
"Development Status :: 4 - Beta",
7175
"Intended Audience :: Developers",
7276
"Topic :: Software Development :: Libraries",
7377
"Programming Language :: Python :: 3",
78+
"Programming Language :: Python :: 3 :: Only",
7479
"Programming Language :: Python :: 3.6",
7580
"Programming Language :: Python :: 3.7",
7681
"Programming Language :: Python :: 3.8",
7782
"Programming Language :: Python :: 3.9",
83+
"Programming Language :: Python :: 3.10",
7884
"Programming Language :: Python :: Implementation :: PyPy",
7985
],
8086
keywords="api graphql protocol rest relay gql client",

tests/conftest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,10 @@ async def go(app, *, port=None, **kwargs): # type: ignore
102102
# Adding debug logs to websocket tests
103103
for name in [
104104
"websockets.legacy.server",
105-
"gql.transport.websockets",
105+
"gql.transport.aiohttp",
106106
"gql.transport.phoenix_channel_websockets",
107+
"gql.transport.requests",
108+
"gql.transport.websockets",
107109
"gql.dsl",
108110
"gql.utilities.parse_result",
109111
]:

tests/test_graphqlws_subscription.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import asyncio
22
import json
33
import sys
4+
import warnings
45
from typing import List
56

67
import pytest
@@ -742,9 +743,13 @@ def test_graphqlws_subscription_sync_graceful_shutdown(
742743
if count == 5:
743744

744745
# Simulate a KeyboardInterrupt in the generator
745-
asyncio.ensure_future(
746-
client.session._generator.athrow(KeyboardInterrupt)
747-
)
746+
with warnings.catch_warnings():
747+
warnings.filterwarnings(
748+
"ignore", message="There is no current event loop"
749+
)
750+
asyncio.ensure_future(
751+
client.session._generator.athrow(KeyboardInterrupt)
752+
)
748753

749754
count -= 1
750755

tests/test_websocket_subscription.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import asyncio
22
import json
33
import sys
4+
import warnings
45
from typing import List
56

67
import pytest
@@ -531,9 +532,13 @@ def test_websocket_subscription_sync_graceful_shutdown(server, subscription_str)
531532
if count == 5:
532533

533534
# Simulate a KeyboardInterrupt in the generator
534-
asyncio.ensure_future(
535-
client.session._generator.athrow(KeyboardInterrupt)
536-
)
535+
with warnings.catch_warnings():
536+
warnings.filterwarnings(
537+
"ignore", message="There is no current event loop"
538+
)
539+
asyncio.ensure_future(
540+
client.session._generator.athrow(KeyboardInterrupt)
541+
)
537542

538543
count -= 1
539544

tox.ini

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[tox]
22
envlist =
33
black,flake8,import-order,mypy,manifest,
4-
py{36,37,38,39,py3}
4+
py{36,37,38,39,310,py3}
55

66
[pytest]
77
markers = asyncio
@@ -12,6 +12,7 @@ python =
1212
3.7: py37
1313
3.8: py38
1414
3.9: py39
15+
3.10: py310
1516
pypy3: pypy3
1617

1718
[testenv]
@@ -30,7 +31,7 @@ deps = -e.[test]
3031
commands =
3132
pip install -U setuptools
3233
; run "tox -- tests -s" to show output for debugging
33-
py{36,37,39,py3}: pytest {posargs:tests}
34+
py{36,37,39,310,py3}: pytest {posargs:tests}
3435
py{38}: pytest {posargs:tests --cov-report=term-missing --cov=gql}
3536

3637
[testenv:black]

0 commit comments

Comments
 (0)