aospy icon indicating copy to clipboard operation
aospy copied to clipboard

Whither making core objects hashable

Open spencerahill opened this issue 7 years ago • 0 comments

Copying relevant discussion from #111, which merits further discussion here:

Note that converting a list of Model objects to a set relies on aospy core objects being hashable, which they currently are not

This is a good point. IIRC you dealt with hashes some when experimenting with a DB implementation. What’s your take, is it reasonable to consider Proj/Model/Runs immutable & hashable (and therefore fair game to implement hash)? My intuition is yes: I don’t see how the core attributes that differentiate them from others of their same type would change during their lifetimes.

But, now that I think about it, does this require preventing setting of those core attributes after instantiation (i.e. by making them properties and using @property.setter). Consider model1 = Model(‘model’, runs=None, …) followed later by model1.runs = [run1, run2]. Shouldn’t that change the hash? As a concrete example, the Examples page does this with proj.regions.

Indeed, I think we need to think more carefully about this. Typically mutable collections are not hashable; therefore, in the strict sense I think perhaps we'd have to think against making Proj and Model objects hashable.

spencerahill avatar Apr 03 '17 18:04 spencerahill