Last active
December 30, 2024 12:36
-
-
Save AlexWaygood/e860b2262960997624c19c6a3aba24fb to your computer and use it in GitHub Desktop.
`__call__` chaining
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> 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