Created
May 24, 2023 17:18
-
-
Save tsibley/10118bc3a6097c88124b9d31ab77e5d1 to your computer and use it in GitHub Desktop.
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
from typing import NamedTuple | |
class Foo(NamedTuple): | |
name: str | |
def __getattribute__(self, attrname): | |
value = super().__getattribute__(attrname) | |
if attrname in super().__getattribute__("_fields"): | |
return lambda: value | |
else: | |
return value | |
t = Foo("test") | |
print(t) | |
print(t.name) | |
print(t.name()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment