1

I'm experimenting with the Dill package, specifically it's detect module and having some trouble intuitively understanding what's is meant by referents, referers, parents and children.

A reference is a value that enables access to some data.

And referents are objects that are referred to, right?

So in the following code:

class MyClass:
    """A simple example class"""
    i = 12345
    def f(self):
        return 'hello world'

an_instance = MyClass()
an_instance2 = MyClass()
an_instance3 = MyClass()

a_list = [an_instance, an_instance2, an_instance3]

Are an_instance, an_instance2, an_instance3 referents of a_list and would the MyClass also be a referent of a_list, but one level of depth further up the chain?

So, with -> signifying the reference, would the chain of referents look like:

a_list -> an_instance -> MyClass

Would this be viewed as:

grandchild -> child -> Parent

Conversely, is a_list a referrer of an_instance as well as an_instance2, an_instance3 and at another level of depth, MyClass?

Making the chain of referrers:

MyClass -> an_instance -> a_list

And would this also be conceived:

parent -> child -> grandchild

Can someone offer a clear explanation of where references, inheritance and containers do and don't coincide?

Korem
  • 11,383
  • 7
  • 55
  • 72
MikeiLL
  • 6,282
  • 5
  • 37
  • 68
  • 1
    ...what is your question?! You seem to be mixing up inheritance with references. – jonrsharpe Sep 03 '14 at 18:47
  • 1
    If you marry my mother and I marry your mother, then you're my father and I'm your father. This makes you the father of your father, and your own grandfather! – Korem Sep 03 '14 at 18:55
  • 1
    You are also conflating containers and their elements into the mix. – chepner Sep 03 '14 at 19:02
  • @jonrsharpe i think i am mixing up inheritance with references. – MikeiLL Sep 03 '14 at 19:03
  • 1
    The OP is referring specifically to how `dill` refers to parents/children in its `dill.detect` module. That module is used for identifying referrent/referred objects (of a specific type) from some given object. It calls the referred/referrent objects parents/children, respectively. See [here](https://github.com/uqfoundation/dill/blob/master/dill/pointers.py) for the source code, and [here](http://stackoverflow.com/questions/25648945/dill-detect-children-object-types) for the OP's other question that I'm assuming lead to this question. – dano Sep 03 '14 at 19:04
  • @chepner So if I add an `object` to a `list`, the `list` becomes a `container` of the `object`, right? Is the `list` not also a `referrer` to the `object` which it `contains`? – MikeiLL Sep 03 '14 at 19:13

1 Answers1

2

In python, inheritance builds a pointer relationship between the class object and the class instance object. For example, a class instance first checks it's own __dict__ then points back to it's class definition to find any missing attribute. Similarly, instance methods can be seen as partials that are applied over class methods, again giving a pointer relationship to the underlying class method. With python, inheritance is little more than when an object can't find some attribute within itself it looks back to the parent (in the mro) for the missing attribute -- that hierarchy is built through a pointer relationship.

That's about the extent that inheritance and pointer references are the same. Pointer references are much more general.

Mike McKerns
  • 33,715
  • 8
  • 119
  • 139