From 6d98d3d8cebcff5dd8a3ee274d4392d862f20172 Mon Sep 17 00:00:00 2001 From: Fredrik Tolf Date: Thu, 13 Jan 2022 23:24:14 +0100 Subject: [PATCH] data: Replace usymbol/string equivalence with obj __getattr__ implementation. --- coe/data.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/coe/data.py b/coe/data.py index b65dbae..aaa862d 100644 --- a/coe/data.py +++ b/coe/data.py @@ -1,4 +1,5 @@ class symbol(object): + __slots__ = [] isafe = set("abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "$%^&*_=/.") @@ -47,18 +48,15 @@ class symbol(object): return "%s:%s" % (self.quote(self.ns), self.quote(self.name)) class usymbol(symbol): + __slots__ = ["name"] ns = "" + def __init__(self, name): self.name = name - def __hash__(self): - return hash(self.name) - def __eq__(s, o): - if isinstance(o, str): - return s.name == o - return super().__eq__(o) - class nssymbol(symbol): + __slots__ = ["ns", "name"] + def __init__(self, ns, name, *args, **kw): super().__init__(*args, **kw) self.name = name @@ -77,3 +75,8 @@ class obj(object): self.__dict__[key] = val def __delitem__(self, key): del self.__dict__[key] + def __getattr__(self, name): + try: + return self.__dict__[symbol.get("", name)] + except KeyError: + raise AttributeError(name) from None -- 2.11.0