-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Right now I'm using a shortcut for routes that optionally require a timestamp by including it in the POST data, and only calling POST when data is present. This lets me use a POST route and a GET route in the same method.
I thought it'd be neat to combine GET /thread/{thread}/posts
, POST /thread/{thread}/posts
and POST /thread/{thread}/since
into a single function. And it totally would be:
python-scuttle/scuttle/versions/v1.py
Lines 76 to 88 in 3e9ca62
def thread_posts(self, thread_id, *, | |
since=None, limit=20, offset=0, direction='asc'): | |
if since is None: | |
return self._request("thread/{}/posts", thread_id) | |
if isinstance(since, int): | |
data = { | |
'timestamp': since, | |
'limit': limit, | |
'offset': offset, | |
'direction': direction, | |
} | |
return self._request("thread/{}/since", thread_id, data) | |
raise TypeError("`since` must be a UNIX timestamp") |
Problem is, using that method (which works just fine for other routes) I can distinguish between POST since
and GET/POST posts
using since is None
. I can't distinguish between GET posts
and POST posts
, because the data needed for POST is already there in the default kwargs.
I don't want to lose these named kwargs because they're a lifesaver for autocomplete.