diff --git a/aiohttp/client.py b/aiohttp/client.py index dcbdd23dfd4..dd55e6e615d 100644 --- a/aiohttp/client.py +++ b/aiohttp/client.py @@ -383,9 +383,9 @@ def __init_subclass__(cls: type["ClientSession"]) -> None: f"Inheritance class {cls.__name__} from ClientSession " "is forbidden" ) - def __del__(self, _warnings: Any = warnings) -> None: + def __del__(self, warnings_warn: Any = warnings.warn) -> None: if not self.closed: - _warnings.warn( + warnings_warn( f"Unclosed client session {self!r}", ResourceWarning, source=self, diff --git a/aiohttp/client_reqrep.py b/aiohttp/client_reqrep.py index 0d6f435b6e5..a6b4845ec6b 100644 --- a/aiohttp/client_reqrep.py +++ b/aiohttp/client_reqrep.py @@ -352,7 +352,7 @@ def content_disposition(self) -> ContentDisposition | None: filename = multipart.content_disposition_filename(params) return ContentDisposition(disposition_type, params, filename) - def __del__(self, _warnings: Any = warnings) -> None: + def __del__(self, warnings_warn: Any = warnings.warn) -> None: if self._closed: return @@ -361,7 +361,7 @@ def __del__(self, _warnings: Any = warnings) -> None: self._cleanup_writer() if self._loop.get_debug(): - _warnings.warn( + warnings_warn( f"Unclosed response {self!r}", ResourceWarning, source=self ) context = {"client_response": self, "message": "Unclosed response"} diff --git a/aiohttp/connector.py b/aiohttp/connector.py index 0b6081f8e08..92b0382b8ac 100644 --- a/aiohttp/connector.py +++ b/aiohttp/connector.py @@ -132,11 +132,9 @@ def __init__( def __repr__(self) -> str: return f"Connection<{self._key}>" - def __del__(self, _warnings: Any = warnings) -> None: + def __del__(self, warnings_warn: Any = warnings.warn) -> None: if self._protocol is not None: - _warnings.warn( - f"Unclosed connection {self!r}", ResourceWarning, source=self - ) + warnings_warn(f"Unclosed connection {self!r}", ResourceWarning, source=self) if self._loop.is_closed(): return