Skip to content

Class based patch API #429

@kai3341

Description

@kai3341

Description

What do you think about API like this:

from patchy import patch
from typing import Callable

class Patch:
    target: Callable

    def __init_subclass__(cls) -> None:
        diff_u = cls.__doc__.strip("\n")
        patch(cls.target, diff_u)

And usage example:

class PatchHandleUpdates(Patch):
    """
    @@ -1,8 +1,8 @@
     async def handle_updates(self, updates):
         if isinstance(updates, (raw.types.Updates, raw.types.UpdatesCombined)):
             is_min = any((
    -            await self.fetch_peers(updates.users),
    -            await self.fetch_peers(updates.chats),
    +            await self.fetch_peers__users(updates.users),
    +            await self.fetch_peers__chats(updates.chats),
             ))

             users = {u.id: u for u in updates.users}
    """

    target = Client.handle_updates

TODO:

  • Maybe add explicit patch apply / rollback
    • It would require explicit methods apply and rollback instead of my implementation
  • Maybe something else?
    • Yes. Ability to add any name into globals. It require API change

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions