Skip to content

Instantly share code, notes, and snippets.

@tsibley
Created May 24, 2023 17:18
Show Gist options
  • Save tsibley/10118bc3a6097c88124b9d31ab77e5d1 to your computer and use it in GitHub Desktop.
Save tsibley/10118bc3a6097c88124b9d31ab77e5d1 to your computer and use it in GitHub Desktop.
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