Skip to content

Commit 2a9b6d9

Browse files
committed
docs(http): add more examples & fix a few issues in docs
1 parent 73f19d5 commit 2a9b6d9

File tree

4 files changed

+50
-3
lines changed

4 files changed

+50
-3
lines changed

nextcore/http/bucket.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@
4343
class Bucket:
4444
"""A discord rate limit implementation around a bucket.
4545
46+
**Example usage**
47+
48+
.. code-block:: python3
49+
50+
bucket_metadata = BucketMetadata()
51+
bucket = Bucket(bucket_metadata)
52+
53+
async with bucket.acquire():
54+
# Do request
55+
await bucket.update(remaining, reset_after_seconds, unlimited=False)
56+
4657
Parameters
4758
----------
4859
metadata:
@@ -52,6 +63,8 @@ class Bucket:
5263
----------
5364
metadata:
5465
The metadata for the bucket.
66+
67+
This should also be updated with info that applies to all buckets like limit and if it is unlimited.
5568
"""
5669

5770
def __init__(self, metadata: BucketMetadata):
@@ -68,6 +81,14 @@ def __init__(self, metadata: BucketMetadata):
6881
async def acquire(self, *, priority: int = 0, wait: bool = True) -> AsyncIterator[None]:
6982
"""Use a spot in the rate limit.
7083
84+
**Example usage**
85+
86+
.. code-block:: python3
87+
88+
async with bucket.acquire():
89+
# Do request
90+
await bucket.update(remaining, reset_after_seconds, unlimited=False)
91+
7192
Parameters
7293
----------
7394
priority:
@@ -212,7 +233,10 @@ def _release_pending(self, max_count: int | None = None):
212233

213234
@property
214235
def dirty(self) -> bool:
215-
"""Whether the bucket is currently any different from a clean bucket created from a :class:`BucketMetadata`."""
236+
"""Whether the bucket is currently any different from a clean bucket created from a :class:`BucketMetadata`.
237+
238+
This can be for example if any requests is being made, or if the bucket is waiting for a reset.
239+
"""
216240
if self._reserved:
217241
return True # Currently doing a request.
218242

nextcore/http/bucket_metadata.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,19 @@
3232
class BucketMetadata:
3333
"""Metadata about a discord bucket.
3434
35+
**Example usage**
36+
37+
.. code-block:: python3
38+
39+
bucket_metadata = BucketMetadata()
40+
bucket = Bucket(bucket_metadata)
41+
42+
async with bucket.acquire():
43+
...
44+
45+
bucket_metadata.limit = 5 # This can be found in the response headers from discord.
46+
bucket_metadata.unlimited = False
47+
3548
Parameters
3649
----------
3750
limit:

nextcore/http/request_session.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,23 @@ class RequestSession:
3535
3636
Parameters
3737
----------
38+
priority:
39+
The priority of the request. Lower is better!
3840
unlimited:
3941
If this request was made when the bucket was unlimited.
4042
4143
This exists to make sure that there is no bad state when switching between unlimited and limited.
4244
4345
Attributes
4446
----------
47+
pending_future:
48+
The future that when set will execute the request.
49+
priority:
50+
The priority of the request. Lower is better!
4551
unlimited:
4652
If this request was made when the bucket was unlimited.
4753
4854
This exists to make sure that there is no bad state when switching between unlimited and limited.
49-
pending_future:
50-
The future that when set will execute the request.
5155
"""
5256

5357
__slots__: Final[tuple[str, ...]] = ("pending_future", "priority", "unlimited")

nextcore/http/route.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@
3535
class Route:
3636
"""Metadata about a discord API route
3737
38+
**Example usage**
39+
40+
.. code-block:: python3
41+
42+
route = Route("GET", "/guilds/{guild_id}", guild_id=1234567890)
43+
3844
Parameters
3945
----------
4046
method:

0 commit comments

Comments
 (0)