diff --git a/CHANGES/9171.misc.rst b/CHANGES/9171.misc.rst new file mode 100644 index 00000000000..c6742edd891 --- /dev/null +++ b/CHANGES/9171.misc.rst @@ -0,0 +1,3 @@ +Improved performance of determining if a URL is absolute -- by :user:`bdraco`. + +The property :attr:`~yarl.URL.absolute` is more performant than the method ``URL.is_absolute()`` and preferred when newer versions of yarl are used. diff --git a/aiohttp/client.py b/aiohttp/client.py index da89ee2a790..e50d216cf5a 100644 --- a/aiohttp/client.py +++ b/aiohttp/client.py @@ -444,7 +444,7 @@ def _build_url(self, str_or_url: StrOrURL) -> URL: if self._base_url is None: return url else: - assert not url.is_absolute() and url.path.startswith("/") + assert not url.absolute and url.path.startswith("/") return self._base_url.join(url) async def _request( diff --git a/aiohttp/test_utils.py b/aiohttp/test_utils.py index 01496b6711a..850efcb8b65 100644 --- a/aiohttp/test_utils.py +++ b/aiohttp/test_utils.py @@ -148,7 +148,7 @@ def make_url(self, path: StrOrURL) -> URL: assert self._root is not None url = URL(path) if not self.skip_url_asserts: - assert not url.is_absolute() + assert not url.absolute return self._root.join(url) else: return URL(str(self._root) + str(path)) diff --git a/aiohttp/web_request.py b/aiohttp/web_request.py index eca71e4413a..91fc1f42bfe 100644 --- a/aiohttp/web_request.py +++ b/aiohttp/web_request.py @@ -174,7 +174,7 @@ def __init__( self._version = message.version self._cache: Dict[str, Any] = {} url = message.url - if url.is_absolute(): + if url.absolute: if scheme is not None: url = url.with_scheme(scheme) if host is not None: