[7.x] Remove yarl from [async] extra

Co-authored-by: Seth Michael Larson <[email protected]>
This commit is contained in:
github-actions[bot]
2020-10-13 15:18:07 -05:00
committed by GitHub
co-authored by Seth Michael Larson
parent 9b8cee0199
commit 0cdeeb654a
5 changed files with 49 additions and 13 deletions
+9 -1
View File
@@ -31,6 +31,14 @@
import aiohttp import aiohttp
import aiohttp.client_exceptions as aiohttp_exceptions import aiohttp.client_exceptions as aiohttp_exceptions
import yarl
# We do this because we don't explicitly require 'yarl'
# within our [async] extra any more.
# See AIOHttpConnection.request() for more information why.
try:
import yarl
except ImportError:
yarl = False
__all__ = ["aiohttp", "aiohttp_exceptions", "yarl"] __all__ = ["aiohttp", "aiohttp_exceptions", "yarl"]
+24 -9
View File
@@ -231,15 +231,30 @@ class AIOHttpConnection(AsyncConnection):
method = "GET" method = "GET"
is_head = True is_head = True
# Provide correct URL object to avoid string parsing in low-level code # Top-tier tip-toeing happening here. Basically
url = yarl.URL.build( # because Pip's old resolver is bad and wipes out
scheme=self.scheme, # strict pins in favor of non-strict pins of extras
host=self.hostname, # our [async] extra overrides aiohttp's pin of
port=self.port, # yarl. yarl released breaking changes, aiohttp pinned
path=url_path, # defensively afterwards, but our users don't get
query_string=query_string, # that nice pin that aiohttp set. :( So to play around
encoded=True, # this super-defensively we try to import yarl, if we can't
) # then we pass a string into ClientSession.request() instead.
if yarl:
# Provide correct URL object to avoid string parsing in low-level code
url = yarl.URL.build(
scheme=self.scheme,
host=self.hostname,
port=self.port,
path=url_path,
query_string=query_string,
encoded=True,
)
else:
url = self.url_prefix + url
if query_string:
url = "%s?%s" % (url, query_string)
url = self.host + url
timeout = aiohttp.ClientTimeout( timeout = aiohttp.ClientTimeout(
total=timeout if timeout is not None else self.timeout total=timeout if timeout is not None else self.timeout
+1 -1
View File
@@ -63,7 +63,7 @@ def lint(session):
# Make sure we don't require aiohttp to be installed for users to # Make sure we don't require aiohttp to be installed for users to
# receive type hint information from mypy. # receive type hint information from mypy.
session.run("python", "-m", "pip", "uninstall", "--yes", "aiohttp", "yarl") session.run("python", "-m", "pip", "uninstall", "--yes", "aiohttp")
session.run("mypy", "--strict", "elasticsearch/") session.run("mypy", "--strict", "elasticsearch/")
session.run("mypy", "--strict", "test_elasticsearch/test_types/sync_types.py") session.run("mypy", "--strict", "test_elasticsearch/test_types/sync_types.py")
+2 -2
View File
@@ -38,7 +38,7 @@ packages = [
] ]
install_requires = [ install_requires = [
"urllib3>=1.21.1", "urllib3>=1.21.1, <2",
"certifi", "certifi",
] ]
tests_require = [ tests_require = [
@@ -49,7 +49,7 @@ tests_require = [
"pytest", "pytest",
"pytest-cov", "pytest-cov",
] ]
async_require = ["aiohttp>=3,<4", "yarl"] async_require = ["aiohttp>=3,<4"]
docs_require = ["sphinx<1.7", "sphinx_rtd_theme"] docs_require = ["sphinx<1.7", "sphinx_rtd_theme"]
generate_require = ["black", "jinja2"] generate_require = ["black", "jinja2"]
@@ -41,3 +41,16 @@ class TestBulk:
assert response["errors"] is False assert response["errors"] is False
assert len(response["items"]) == 1 assert len(response["items"]) == 1
class TestYarlMissing:
async def test_aiohttp_connection_works_without_yarl(
self, async_client, monkeypatch
):
# This is a defensive test case for if aiohttp suddenly stops using yarl.
from elasticsearch._async import http_aiohttp
monkeypatch.setattr(http_aiohttp, "yarl", False)
resp = await async_client.info(pretty=True)
assert isinstance(resp, dict)