From c41e21366e47f60b49644ceef6f602c81fbd0d65 Mon Sep 17 00:00:00 2001 From: Jakob Keller <57402305+jakob-keller@users.noreply.github.com> Date: Fri, 20 Oct 2023 15:51:55 +0200 Subject: [PATCH] Apply `requests` best practices (#8558) --- src/poetry/publishing/uploader.py | 6 ++---- src/poetry/repositories/pypi_repository.py | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/poetry/publishing/uploader.py b/src/poetry/publishing/uploader.py index 94b12e92ac0..c10b49bf513 100644 --- a/src/poetry/publishing/uploader.py +++ b/src/poetry/publishing/uploader.py @@ -77,7 +77,7 @@ def auth(self, username: str | None, password: str | None) -> None: self._password = password def make_session(self) -> requests.Session: - session = requests.session() + session = requests.Session() auth = self.get_auth() if auth is not None: session.auth = auth @@ -106,10 +106,8 @@ def upload( if client_cert: session.cert = str(client_cert) - try: + with session: self._upload(session, url, dry_run, skip_existing) - finally: - session.close() def post_data(self, file: Path) -> dict[str, Any]: meta = Metadata.from_package(self._package) diff --git a/src/poetry/repositories/pypi_repository.py b/src/poetry/repositories/pypi_repository.py index cf63e3c37bd..e23a2f96976 100644 --- a/src/poetry/repositories/pypi_repository.py +++ b/src/poetry/repositories/pypi_repository.py @@ -49,7 +49,7 @@ def __init__( def search(self, query: str) -> list[Package]: results = [] - response = requests.session().get( + response = requests.get( self._base_url + "search", params={"q": query}, timeout=REQUESTS_TIMEOUT ) parser = SearchResultParser()