Skip to content
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

Add support for Python 3.10 #5927

Merged
merged 10 commits into from
Oct 8, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
needs: lint
strategy:
matrix:
pyver: [3.7, 3.8, 3.9]
pyver: [3.7, 3.8, 3.9, '3.10']
no-extensions: ['', 'Y']
os: [ubuntu, macos, windows]
exclude:
Expand Down
1 change: 1 addition & 0 deletions CHANGES/5927.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for Python 3.10 in Github Action and fix the warning.
webknjaz marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 3 additions & 1 deletion aiohttp/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -876,9 +876,11 @@ def _make_ssl_context(verified: bool) -> SSLContext:
if verified:
return ssl.create_default_context()
else:
sslcontext = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
sslcontext = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
sslcontext.options |= ssl.OP_NO_SSLv2
sslcontext.options |= ssl.OP_NO_SSLv3
sslcontext.check_hostname = False
sslcontext.verify_mode = ssl.CERT_NONE
try:
sslcontext.options |= ssl.OP_NO_COMPRESSION
except AttributeError as attr_err:
Expand Down
6 changes: 4 additions & 2 deletions aiohttp/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,10 @@ def get_app(self) -> Application:
raise RuntimeError("Did you forget to define get_application()?")

def setUp(self) -> None:
if PY_38:
self.loop = asyncio.get_event_loop()
try:
self.loop = asyncio.get_running_loop()
except RuntimeError:
self.loop = asyncio.get_event_loop_policy().get_event_loop()

self.loop.run_until_complete(self.setUpAsync())

Expand Down
2 changes: 1 addition & 1 deletion docs/third_party.rst
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,6 @@ ask to raise the status.

- `aiohttp-retry <https://github.com/inyutin/aiohttp_retry>`_
Wrapper for aiohttp client for retrying requests. Python 3.6+ required.

Hanaasagi marked this conversation as resolved.
Show resolved Hide resolved
- `aiohttp-socks <https://github.com/romis2012/aiohttp-socks>`_
SOCKS proxy connector for aiohttp.
6 changes: 3 additions & 3 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ pyparsing==2.4.7
# via
# -r requirements/lint.txt
# packaging
pytest==6.2.2
pytest==6.2.5
# via
# -r requirements/lint.txt
# -r requirements/test.txt
Expand Down Expand Up @@ -223,7 +223,7 @@ requests==2.25.1
# sphinx
setuptools-git==1.2
# via -r requirements/test.txt
six==1.15.0
six==1.16.0
# via
# -r requirements/lint.txt
# cryptography
Expand Down Expand Up @@ -299,7 +299,7 @@ yarl==1.6.3
# via -r requirements/base.txt

# The following packages are considered to be unsafe in a requirements file:
setuptools==51.3.1
setuptools==57.4.0
# via
# blockdiag
# gunicorn
Expand Down
2 changes: 1 addition & 1 deletion requirements/lint.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ flake8-pyi==20.10.0
isort==5.9.3
mypy==0.910; implementation_name=="cpython"
pre-commit==2.15.0
pytest==6.2.2
pytest==6.2.5
types-chardet==0.1.3
4 changes: 2 additions & 2 deletions requirements/lint.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ pyflakes==2.3.0
# flake8-pyi
pyparsing==2.4.7
# via packaging
pytest==6.2.2
pytest==6.2.5
# via -r requirements/lint.in
pyyaml==5.4.1
# via pre-commit
regex==2020.11.13
# via black
six==1.15.0
six==1.16.0
# via virtualenv
toml==0.10.2
# via
Expand Down
2 changes: 1 addition & 1 deletion requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ freezegun==1.1.0
mypy==0.910; implementation_name=="cpython"
mypy-extensions==0.4.3; implementation_name=="cpython"
proxy.py==2.3.1
pytest==6.2.2
pytest==6.2.5
pytest-cov==3.0.0
pytest-mock==3.6.1
re-assert==1.1.0
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def tls_certificate(tls_certificate_authority: Any) -> Any:

@pytest.fixture
def ssl_ctx(tls_certificate: Any) -> ssl.SSLContext:
ssl_ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
ssl_ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
tls_certificate.configure_cert(ssl_ctx)
return ssl_ctx

Expand Down
2 changes: 1 addition & 1 deletion tests/test_client_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -2348,7 +2348,7 @@ def create(url: URL, srv: Any):
cert = tls_certificate_authority.issue_cert(
url.host, "localhost", "127.0.0.1"
)
ssl_ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
ssl_ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
cert.configure_cert(ssl_ctx)
kwargs["ssl"] = ssl_ctx
return aiohttp_server(app, **kwargs)
Expand Down
14 changes: 9 additions & 5 deletions tests/test_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ async def go(app):

def create_mocked_conn(conn_closing_result: Optional[Any] = None, **kwargs: Any):
assert "loop" not in kwargs
loop = asyncio.get_event_loop()
try:
loop = asyncio.get_running_loop()
except RuntimeError:
loop = asyncio.get_event_loop_policy().get_event_loop()

proto = mock.Mock(**kwargs)
proto.closed = loop.create_future()
proto.closed.set_result(conn_closing_result)
Expand Down Expand Up @@ -1267,7 +1271,7 @@ async def test___get_ssl_context1(loop: Any) -> None:


async def test___get_ssl_context2(loop: Any) -> None:
ctx = ssl.SSLContext()
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
conn = aiohttp.TCPConnector()
req = mock.Mock()
req.is_ssl.return_value = True
Expand All @@ -1276,7 +1280,7 @@ async def test___get_ssl_context2(loop: Any) -> None:


async def test___get_ssl_context3(loop: Any) -> None:
ctx = ssl.SSLContext()
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
conn = aiohttp.TCPConnector(ssl=ctx)
req = mock.Mock()
req.is_ssl.return_value = True
Expand All @@ -1285,7 +1289,7 @@ async def test___get_ssl_context3(loop: Any) -> None:


async def test___get_ssl_context4(loop: Any) -> None:
ctx = ssl.SSLContext()
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
conn = aiohttp.TCPConnector(ssl=ctx)
req = mock.Mock()
req.is_ssl.return_value = True
Expand All @@ -1294,7 +1298,7 @@ async def test___get_ssl_context4(loop: Any) -> None:


async def test___get_ssl_context5(loop: Any) -> None:
ctx = ssl.SSLContext()
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
conn = aiohttp.TCPConnector(ssl=ctx)
req = mock.Mock()
req.is_ssl.return_value = True
Expand Down
6 changes: 3 additions & 3 deletions tests/test_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ async def test_on_startup_hook(self) -> None:
self.assertTrue(self.on_startup_called)

def test_default_loop(self) -> None:
self.assertIs(self.loop, asyncio.get_event_loop())
self.assertIs(self.loop, asyncio.get_event_loop_policy().get_event_loop())


def test_default_loop(loop: Any) -> None:
assert asyncio.get_event_loop() is loop
assert asyncio.get_event_loop_policy().get_event_loop() is loop


@pytest.mark.xfail(not PY_38, reason="ThreadedChildWatcher is only available in 3.8+")
Expand All @@ -53,7 +53,7 @@ def test_setup_loop_non_main_thread() -> None:
def target() -> None:
try:
with loop_context() as loop:
assert asyncio.get_event_loop() is loop
assert asyncio.get_event_loop_policy().get_event_loop() is loop
loop.run_until_complete(test_subprocess_co(loop))
except Exception as exc:
nonlocal child_exc
Expand Down
6 changes: 3 additions & 3 deletions tests/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def test__create_ssl_context_without_certs_and_ciphers(
worker,
tls_certificate_pem_path,
) -> None:
worker.cfg.ssl_version = ssl.PROTOCOL_SSLv23
worker.cfg.ssl_version = ssl.PROTOCOL_TLS_CLIENT
worker.cfg.cert_reqs = ssl.CERT_OPTIONAL
worker.cfg.certfile = tls_certificate_pem_path
worker.cfg.keyfile = tls_certificate_pem_path
Expand All @@ -264,7 +264,7 @@ def test__create_ssl_context_with_ciphers(
worker,
tls_certificate_pem_path,
) -> None:
worker.cfg.ssl_version = ssl.PROTOCOL_SSLv23
worker.cfg.ssl_version = ssl.PROTOCOL_TLS_CLIENT
worker.cfg.cert_reqs = ssl.CERT_OPTIONAL
worker.cfg.certfile = tls_certificate_pem_path
worker.cfg.keyfile = tls_certificate_pem_path
Expand All @@ -279,7 +279,7 @@ def test__create_ssl_context_with_ca_certs(
tls_ca_certificate_pem_path,
tls_certificate_pem_path,
) -> None:
worker.cfg.ssl_version = ssl.PROTOCOL_SSLv23
worker.cfg.ssl_version = ssl.PROTOCOL_TLS_CLIENT
worker.cfg.cert_reqs = ssl.CERT_OPTIONAL
worker.cfg.certfile = tls_certificate_pem_path
worker.cfg.keyfile = tls_certificate_pem_path
Expand Down