UNO: determine if 2 objects refer to the same thing

I’m taking a stub at implementing this question, but when traversing UNO hierarchy I’ll need to keep track of things came across.

The usual way in python to determine if 2 objects are the same (as in, not in terms of properties and values, but really are the same thing) is id() function, but…

>>> list_of_same_objects = [model.CurrentController.ActiveSheet for i in range(0,10)]
>>> [id(obj) for obj in list_of_same_objects]
[140159220049672, 140159220049696, 140159220049720, 140159220049744, 140159220049768, 140159220049792, 140159220049816, 140159220049840, 140159220049864, 140159220049888]

Oops. These are the same objects, and yet id() says otherwise. Using plain == doesn’t work either btw. How do I determine that then?

I believe that at this point, you really need to stop trying to reverse-engineer all the stuff, and start reading the code.

@MikeKaganski do I understand correctly that you say that not with relation to “determining if 2 objects are the same” question, but to my questions lately in general? In this case, I don’t see how looking at the code may be useful. I mean: every question I stumble upon come down to “I see a thing in LO, how do I reach it programmatically”. Most of the times I can use MRI to determine name of the “thing” to look up docs (or I can just guess it, and query a search engine). So this is mostly not a problem. However, determining “how do I reach the thing from top-level” is always a problem, and… I just don’t see, how to figure out hierarchy to the “thing” from the code. But maybe it’s just because I’m not familiar with the codebase, do you think it indeed could help…?

Ah, nvm, I haven’t figured you put the getActiveSheet() link because I referred to ActiveSheet property in the question as an example (I forgot about it). (oops, for some reason can’t remove my prev. comment :confused: Oh, well) Hmm…Does it say, the function returns a new object on every access? Sounds inefficient.

I say it both in relation to the specific question (“determining if 2 objects are the same”), and in general. Wrt the first question - reading the code, you may find out that the cell range UNO objects are not some objects existing in the Calc document model. E.g., there’s no “cell” object there; instead, a cell data and properties are spread across several data structures inside “column” object. Likewise, there’s no “row” object (a row is just data related to same cells in all columns of a table). So the light-weight objects are created for each range you need each time you ask for them; and having each object to only be created once would require at least some manager keeping track of such things (with an overhead to search for instances instead of overhead of light-weight object creation).

In general, I do think that it could help. Because it’s in the code where the objects get created, and you indeed can find places where relevant ctors are called.