Jupyterhub: Question: Why are there two different classes with the name `Spawner`?

Created on 21 May 2018  路  2Comments  路  Source: jupyterhub/jupyterhub

While trying to understand the source code for what seems to be JupyterHub's "main" Spawner class which inherits from LoggingConfigurable and is found in spawner.py, I recently stumbled upon the existence of another class called Spawner in orm.py which inherits from Base.

What is the purpose of the second class? Its docstring just says "State about a Spawner". This confuses me further since the class name is Spawner, and not SpawnerState or something like that, which would seem to agree more with the docstring.

Is an instance of the Spawner(Base) class supposed to be the object-to-relational mapping applied to an instance of the Spawner(LoggingConfigurable class? Why do they have the same name?

How are the two classes distinguished from each other elsewhere in the code base? Is the convention for using an instance of the Spawner(Base) class to write from jupyterhub import orm in the preamble and then use orm.Spawner in the body? (E.g. as is done here?)

Sorry in advance for the stupid question.

question

Most helpful comment

The classes in orm.py describe the ORM data and relationships for each object. For more complex objects (User, Spawner), there is a higher-level class that wraps the orm object (rather than subclassing the ORM types). The ORM objects use Entity names rather than 'EntityState' because that seems to be the convention of ORMs. You can think of orm.Spawner as the subset of Spawner that lives in the database.

How are the two classes distinguished from each other elsewhere in the code base?

Typically, orm objects are referred to as orm_spawner, etc. in context to distinguish them from the higher-level objects.

All 2 comments

The classes in orm.py describe the ORM data and relationships for each object. For more complex objects (User, Spawner), there is a higher-level class that wraps the orm object (rather than subclassing the ORM types). The ORM objects use Entity names rather than 'EntityState' because that seems to be the convention of ORMs. You can think of orm.Spawner as the subset of Spawner that lives in the database.

How are the two classes distinguished from each other elsewhere in the code base?

Typically, orm objects are referred to as orm_spawner, etc. in context to distinguish them from the higher-level objects.

Thank you for the feedback! This makes more sense to me now; I really appreciate it!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

statueofmike picture statueofmike  路  27Comments

dsblank picture dsblank  路  23Comments

ckbhatt picture ckbhatt  路  28Comments

danielballan picture danielballan  路  50Comments

SteveFelker picture SteveFelker  路  38Comments