2 deleted 213 characters in body
source | link

With the below structure you could still use the call you provided of client.some_category.some_api_call(some_arg, other_arg)

Here it is:

class _Category:
    def __init__(self, client):
        self._client = client

    # another forwarding method
    async def _make_call(*args, **kwargs):
        return await self._client._make_call(*args, **kwargs)

class _SomeCategory(_Category):
    async def some_api_call(some_arg, other_arg):
        return await self._make_call(blah blah)

    async def other_api_call(some_arg, other_arg):
        if some_arg.some_condition():
            other_arg.whatever_logic_here()
        return await self._make_call(yadda yadda)

class _OtherCategory(_Category):
    async def yet_another_api_call(some_arg, other_arg, yet_another_arg):
        #...
        return await self._make_call # etc etc

class ApiClient:
    def __init__(self, connection):
        self._connection = connection
        self.some_category = _SomeCategory()
        self.other_category = _OtherCategory()

    # forwarding method
    async def _make_call(*args, **kwargs):
        return await self._connection._make_call(*args, **kwargs)

In my reading I came across the idea that when a class has only "verbs", or action methods, (like your _SomeCategory class) it is a sign that your class should perhaps be a part of another class. Just a side note.

With the below structure you could still use the call you provided of client.some_category.some_api_call(some_arg, other_arg)

Here it is:

class _Category:
    def __init__(self, client):
        self._client = client

    # another forwarding method
    async def _make_call(*args, **kwargs):
        return await self._client._make_call(*args, **kwargs)

class _SomeCategory(_Category):
    async def some_api_call(some_arg, other_arg):
        return await self._make_call(blah blah)

    async def other_api_call(some_arg, other_arg):
        if some_arg.some_condition():
            other_arg.whatever_logic_here()
        return await self._make_call(yadda yadda)

class _OtherCategory(_Category):
    async def yet_another_api_call(some_arg, other_arg, yet_another_arg):
        #...
        return await self._make_call # etc etc

class ApiClient:
    def __init__(self, connection):
        self._connection = connection
        self.some_category = _SomeCategory()
        self.other_category = _OtherCategory()

    # forwarding method
    async def _make_call(*args, **kwargs):
        return await self._connection._make_call(*args, **kwargs)

In my reading I came across the idea that when a class has only "verbs", or action methods, (like your _SomeCategory class) it is a sign that your class should perhaps be a part of another class. Just a side note.

With the below structure you could still use the call you provided of client.some_category.some_api_call(some_arg, other_arg)

Here it is:

class _Category:
    def __init__(self, client):
        self._client = client

    # another forwarding method
    async def _make_call(*args, **kwargs):
        return await self._client._make_call(*args, **kwargs)

class _SomeCategory(_Category):
    async def some_api_call(some_arg, other_arg):
        return await self._make_call(blah blah)

    async def other_api_call(some_arg, other_arg):
        if some_arg.some_condition():
            other_arg.whatever_logic_here()
        return await self._make_call(yadda yadda)

class _OtherCategory(_Category):
    async def yet_another_api_call(some_arg, other_arg, yet_another_arg):
        #...
        return await self._make_call # etc etc

class ApiClient:
    def __init__(self, connection):
        self._connection = connection
        self.some_category = _SomeCategory()
        self.other_category = _OtherCategory()

    # forwarding method
    async def _make_call(*args, **kwargs):
        return await self._connection._make_call(*args, **kwargs)
1
source | link

With the below structure you could still use the call you provided of client.some_category.some_api_call(some_arg, other_arg)

Here it is:

class _Category:
    def __init__(self, client):
        self._client = client

    # another forwarding method
    async def _make_call(*args, **kwargs):
        return await self._client._make_call(*args, **kwargs)

class _SomeCategory(_Category):
    async def some_api_call(some_arg, other_arg):
        return await self._make_call(blah blah)

    async def other_api_call(some_arg, other_arg):
        if some_arg.some_condition():
            other_arg.whatever_logic_here()
        return await self._make_call(yadda yadda)

class _OtherCategory(_Category):
    async def yet_another_api_call(some_arg, other_arg, yet_another_arg):
        #...
        return await self._make_call # etc etc

class ApiClient:
    def __init__(self, connection):
        self._connection = connection
        self.some_category = _SomeCategory()
        self.other_category = _OtherCategory()

    # forwarding method
    async def _make_call(*args, **kwargs):
        return await self._connection._make_call(*args, **kwargs)

In my reading I came across the idea that when a class has only "verbs", or action methods, (like your _SomeCategory class) it is a sign that your class should perhaps be a part of another class. Just a side note.