Skip to content

Commit

Permalink
Client.close()
Browse files Browse the repository at this point in the history
  • Loading branch information
jwodder committed Nov 10, 2023
1 parent ddc984b commit c6b5973
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ v0.3.0 (in development)
`Client` without having to use a custom `Session`
- Added a `headers` argument to the `Client` constructor for setting arbitrary
additional headers without having to use a custom `Session`
- Gave `Client` a `close()` method

v0.2.0 (2023-11-03)
-------------------
Expand Down
10 changes: 10 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,16 @@ which case the elements of that list are yielded); otherwise, an error occurs.
If ``raw`` is ``True``, then instead of yielding each page's items, the
returned iterator will yield each page as a ``requests.Response`` object.

.. code:: python
Client.close() -> None
Close the client's internal ``requests.Session``. No more request methods may
be called afterwards.

This method is called automatically on exit when using ``Client`` as a context
manager.

.. code:: python
class Endpoint:
Expand Down
12 changes: 11 additions & 1 deletion src/ghreq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def __exit__(
_exc_val: BaseException | None,
_exc_tb: TracebackType | None,
) -> None:
self.session.close()
self.close()

def __truediv__(self, path: str) -> Endpoint:
return Endpoint(self, joinurl(self.api_url, path))
Expand Down Expand Up @@ -514,6 +514,16 @@ def paginate(
path = r.links.get("next", {}).get("url")
params = None

def close(self) -> None:
"""
Close the client's internal `requests.Session`. No more request
methods may be called afterwards.
This method is called automatically on exit when using `Client` as a
context manager.
"""
self.session.close()


@dataclass
class Endpoint:
Expand Down

0 comments on commit c6b5973

Please sign in to comment.