so I'm working on a class for a vector which I want to hash like a tuple, and to do so, a vector instance needs acess to it's properties.
here's the constructor for the performative properties I'm using, and the vector class:
def newProp():
newdict = {}
getter = newdict.get
setter = newdict.__setitem__
def wrapper(vec,val):
if val is None: return
vtype = val.__class__
if vtype is str: setter(vec, float(val) ); return
if numtype(vtype): setter(vec,val)
return property(getter, wrapper)
class vector(object):
__slots__ = []
X = newProp()
Y = newProp()
Z = newProp()
W = newProp()
def __init__(vec,*other): # other is for special initialization
vec.X = vec.Y = vec.Z = vec.W = None
def __hash__(vec): return hash( (vec.X, vec.Y, vec.Z, vec.W) )
now there's alot to be questioned, particularly because I don't know everything about how Python works...
but this is just the most performative approach I could think of for an automated vector class.
the problem I'm getting is hash(vector()) leads to a recursion error since dict.get calls vec.hash for each property.
I'm looking for a workaround that's just as performative or better.
thanks. :)