Skip to content

Instantly share code, notes, and snippets.

@AlexWaygood
Last active December 30, 2024 12:36
Show Gist options
  • Save AlexWaygood/e860b2262960997624c19c6a3aba24fb to your computer and use it in GitHub Desktop.
Save AlexWaygood/e860b2262960997624c19c6a3aba24fb to your computer and use it in GitHub Desktop.
`__call__` chaining
>>> class Foo:
... def __call__(self):
... return 42
...
>>> class Bar:
... __call__ = Foo()
...
>>> class Baz:
... __call__ = Bar()
...
>>> class Spam:
... __call__ = Baz()
...
>>> spam_instance = Spam()
>>> spam_instance()
42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment