Skip to content

Instantly share code, notes, and snippets.

@brettcannon
Created December 4, 2023 22:54
Show Gist options
  • Save brettcannon/49ec8201cb95ff37b6dae9197ece86ea to your computer and use it in GitHub Desktop.
Save brettcannon/49ec8201cb95ff37b6dae9197ece86ea to your computer and use it in GitHub Desktop.
Provide a function that lets you use a fluent-style API when a method returns e.g. `None` instead of `self`
def fluent(bound_method, /, *args, **kwargs):
"""Call a bound method and return `self` from that method."""
bound_method(*args, **kwargs)
return bound_method.__self__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment