Last active
October 2, 2019 10:25
-
-
Save jacksmith15/515df6f060f7c551d1e77b1d0bd7bf88 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 collections import namedtuple | |
class ImmutableNamespaceMeta(type): | |
def __new__(cls, name, bases, dct): | |
x = super().__new__(cls, name, bases, dct) | |
public = {key: value for key, value in dct.items() if not key.startswith("_")} | |
typ_ = namedtuple(name + "Type", public.keys()) | |
return typ_(**public) | |
class ImmutableNamespace(metaclass=ImmutableNamespaceMeta): | |
FOO = 3 | |
BAR = "baz" | |
# TODO(Inheritance doesn't work) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment