Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confused about self.parent #840

Open
metaperl opened this issue Mar 29, 2023 · 1 comment
Open

Confused about self.parent #840

metaperl opened this issue Mar 29, 2023 · 1 comment

Comments

@metaperl
Copy link
Contributor

Hello, I am making heavy use of self.parent in some code I wrote, but:

  1. searching the docs does not define parent
  2. searching the repo for def parent does not yield any results
  3. There are a number of red herrings in the search to understand what self.parent does and where it is documented because of toy examples in the issues and the docs where we have class Child and Class Parent where the Child class has a slot accessed via self.parent ... this is not the self.parent that is being heavily used in my Traitlets-based applications... but for the life of me, I cannot remember why I started using it and what the semantics are.

Actually I think I found it : it's defined as "The parent Configurable instance of this object." ... ah I think I know the purpose of this... it's to get at the Application class that is the parent of the Configurable class so that you can access slots within the Application... is that correct?

@rmorshea
Copy link
Contributor

rmorshea commented Mar 30, 2023

From my understanding, parent is not necessarily the root application instance. Tartlets allows configurables to be arbitrarily nested. Consider the following

cfg = Config(...) 
c1 = Class1(config=cfg)
c2 = Class2(parent=c1)
c3 = Class3(parent=c1)
assert c3.parent.parent == c1

From Traitlets' internal perspective, the purpose is to allow thecfg to be passed down from the outer-most configurable to any inner configurables so they can be properly initialized. From the perspective of users, this does given you the ability to traverse these parent references to find that outer-most configurable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants