Last active
May 17, 2022 20:51
-
-
Save an-dyy/542170db935d86e6279f7018ef3a5259 to your computer and use it in GitHub Desktop.
This file contains 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
from __future__ import annotations | |
class DictHack: | |
__eq__ = lambda self, other: [other.__setitem__(key, value) for key, value in self.payload.items()] | |
def __init__(self, target: type["Any"], **kwargs: "Any") -> None: | |
self.target = target.__dict__ | |
self.payload = kwargs | |
def __enter__(self) -> DictHack: | |
self.target == self | |
return self | |
def __exit__(self, *_: "Any") -> None: | |
... | |
with DictHack(str, hello=lambda s: print(f"Hello, {s}")): | |
"World!".hello() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment