SynBioDex / pySBOL

SWIG-Python wrappers implementing SBOL 2.2
Apache License 2.0
25 stars 8 forks source link

Enhancement request: Interned objects for python identity #109

Open rpgoldman opened 5 years ago

rpgoldman commented 5 years ago

It seems that a pySBOL Document object can have non-identical objects that correspond to the same URI. I.e., foo != bar but foo.identity == bar.identity. This seems bound to lead to bugs in future code written in pySBOL.

I believe that a solution could be crafted by having a persistent interface the source of the SBOL document, and ensuring that pySBOL objects are treated as interned objects. I.e., if pySBOL receives a request for an SBOL identity that has already been pulled down, pySBOL should return the previous object, instead of creating a new one.

If this is for some reason infeasible, the second best solution would be to disable equality checking for pySBOL objects. Doing so would force the user to equality check the URIs instead of the objects. Apparently this can be achieved by overriding __eq__ and __ne__ (see https://stackoverflow.com/questions/390250/elegant-ways-to-support-equivalence-equality-in-python-classes). This wouldn't be ideal, because sometimes one might want to check for object equality instead of URI identity, hence my preference for interning, which would make object equality and SBOL identity congruent.