Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add boostrap_line_paginator_with_emojis util #262

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

shtlrs
Copy link
Member

@shtlrs shtlrs commented Jul 28, 2024

Closes #261

Copy link

netlify bot commented Jul 28, 2024

Deploy Preview for bot-core ready!

Name Link
🔨 Latest commit 13498a3
🔍 Latest deploy log https://app.netlify.com/sites/bot-core/deploys/66a64361aef6680008c4c17d
😎 Deploy Preview https://deploy-preview-262--bot-core.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@jchristgit
Copy link
Member

Why wouldn't we use a subclass of paginator that takes an additional init arg that it uses in paginate instead? Something like

class CustomPaginationEmojisLinePaginator(LinePaginator):
    def __init__(self, *args, **kwargs) -> None:
        self.pagination_emojis = kwargs.pop("pagination_emojis", ...)  # dunno default
        super().__init__(*args, **kwargs)

    @classmethod
    async def paginate(*args, **kwargs) -> discord.Message | None:
        return await super().paginate(*args, **kwargs, pagination_emojis=self.pagination_emojis)

@shtlrs
Copy link
Member Author

shtlrs commented Aug 16, 2024

@jchristgit I have just your response.

paginate is a class method, i won't be able to access the pagination_emojis instance attribute if I do it like that.

So in this case, you'd still have to pass it each time to the paginate method, which itself instantiates a LinePaginator

@jchristgit
Copy link
Member

What about this?

def boostrap_line_paginator_with_emojis(pagination_emojis: PaginationEmojis) -> type[LinePaginator]:
    """Bootsrap a LinePaginator class with custom emojis."""
    class _LinePaginator(LinePaginator):
        @classmethod
        async def paginate(cls, *args, **kwargs) -> discord.Message | None:
            return await cls.paginate(*args, **kwargs, pagination_emojis=pagination_emojis)

@shtlrs
Copy link
Member Author

shtlrs commented Aug 16, 2024

What about this?

def boostrap_line_paginator_with_emojis(pagination_emojis: PaginationEmojis) -> type[LinePaginator]:
    """Bootsrap a LinePaginator class with custom emojis."""
    class _LinePaginator(LinePaginator):
        @classmethod
        async def paginate(cls, *args, **kwargs) -> discord.Message | None:
            return await cls.paginate(*args, **kwargs, pagination_emojis=pagination_emojis)

Yeah that works, I just want to avoid args and kwargs generally but yeah

@jchristgit
Copy link
Member

Yeah that works, I just want to avoid args and kwargs generally but yeah

Why the hate against args and kwargs?

I think that we should use my solution but I'm biased. @ChrisLovering what do you think?

@shtlrs
Copy link
Member Author

shtlrs commented Aug 24, 2024

Yeah that works, I just want to avoid args and kwargs generally but yeah

Why the hate against args and kwargs?

I think that we should use my solution but I'm biased. @ChrisLovering what do you think?

Because the signature doesn't tell you anything about the function anymore, and the api loses meaning. The only way to find out is to read inside the wrapped method

@jchristgit
Copy link
Member

jchristgit commented Aug 24, 2024 via email

@shtlrs
Copy link
Member Author

shtlrs commented Aug 24, 2024

Hmmmm, not sure about that.

You're exposing a new public interface for your clients, so the maintenance is part of the job. What you're trying to do, wrapping it, adding or removing stuff doesn't matter. I don't know, it just doesn't sit well with me for some reason.

@jchristgit
Copy link
Member

jchristgit commented Aug 24, 2024 via email

@shtlrs
Copy link
Member Author

shtlrs commented Aug 26, 2024

@jchristgit How about we do it like this

from functools import partial


class LinePaginator:

    @classmethod
    def idk_what_to_call_this_but_it_returns_a_new_paginator_with_emojis(cls, emojis):
        paginator = type(cls.__name__, cls.__bases__, dict(cls.__dict__))
        paginator.paginate = partial(paginator.paginate, emojis=emojis)
        return paginator

I think this could work

@jchristgit
Copy link
Member

Yes, that could probably work. But as a casual reader I now need to remember what type did and why it did what it does.

I have no idea what we are doing here, because it's defined in the same module.

Isn't this more straightforward?

def paginate_with_default_emojis(*args, **kwargs):
    kwargs.setdefault("pagination_emojis", ...)
    return LinePaginator.paginate(*args, **kwargs)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bootstrap LinePaginator with trash emoji
2 participants