Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upDraft design #18
Draft design #18
Comments
|
Yes, we can use I like Mixins pattern to split "modules" into separated files. I make a proposal this way. In my opinion, we can try to refact some common parameters that we get in requests (pagination, offset, limit... One dataclass? fields, sort, filter, query... One dataclass?). I think we should try to have a consistent way to deal with input / output objects -> I make a GET request to retrieve a collection, I get an My guess: Start first with modules split (Mixins), then refact common parameters, then deal with consistency |
Here are 2 ways I would see this:
Maybe both strategies can be used together ?
Yes, this is how I was thinking it too. Most api call will only be really simple, so we can wraps some args that serves a specific purpose in dataclasses. I already started to work on this part, but we might need to think a bit more before coding. @dataclass
class Pagination:
limit: int = 100
offset: int = 0
page: Optional[int] = None
def __dict__(self):
result = {"limit": self.limit}
if self.page:
result.update({"page": self.page})
else:
result.update({"offset": self.offset})
return result
# Here is an API call with Pagination
def list(self, pagination: Pagination = None):
passI say this https://www.python.org/dev/peps/pep-0589/#class-based-syntax, but sadly it is really recent, so we would have to drop support for 3.7 which is not acceptable for now. We might move to this once 3.8 is the most used version across all distributions. But the above code should work nicely. |
|
@vvatelot Here is a small snapshot of what I had in mind regarding solution 1: |
I like this approach. This is really straightforward, clean and simple. |
In order to share a common idea on the direction of this package, we should draft/discuss on the design of this package.
Some details are bothering me with the current implementation:
What should we implement first, what should be open for contribution ?
@vvatelot Any thoughts on this one ?