Got it.

As I like to "eat the pudding":
x.py:

class Meta(type):
   print("Here is Meta")
   def __new__(cls, name, bases, dct):
      print("meta.new")
      return super().__new__(cls, name, bases, dct)

class Foo(metaclass=Meta):
   print("Here is Foo")


y.py:

from x import Foo

class What(Foo):
   print("Here's What, a Foo")


Giving as output on python y.py:
Here is Meta
Here is foo
meta.new
Here's What, a Foo
meta.new

Showing that the meta class indeed is called on construction of "What": 
hence there you have the mechanics of class registration.

Now that's covered I've to say I'm not too happy importing module's with no 
apparent use, but that seems the nature of the beast.

Kind regards,
Nacho

 

> The pattern from a software architecture point of view was identified by 
> Martin Fowler as the "registry" pattern, 
> https://martinfowler.com/eaaCatalog/registry.html, however this pattern 
> doesn't say much about the mechanics used.    The registry pattern refers 
> to linking the creation of a class or object to its automatic inclusion in 
> some semi-global or in some cases global registry, which is one SQLAlchemy 
> uses a lot, in some cases explicitly and in other cases only behind the 
> scenes.
>
> The declarative metaclass contains a function which scans your class for 
> attributes, builds a Table from these attributes which is associated with 
> the MetaData collection that the metaclass has access towards (this is 
> registry pattern #1).  Then, the mapper() function is invoked against the 
> class you created along with this Table, which creates a new Mapper object 
> that is added to a global, weak-referencing collection inside the 
> sqlalchemy.orm.mapper module (this is registry pattern #2).  When the 
> mapper "inherits" from another one as seems to be the case here, that 
> inheriting mapper is also amended to include this new mapper in its 
> collection of subclasses.
>
> The overall "mapper configure" step which you may have seen scans through 
> this registry of mapper objects and makes sure all the mappers that refer 
> to each other, usually through the relationship() linkage, are fully linked 
> and have been found.
>
>
>

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/bac20779-de45-4889-9a03-25f0d4fd20b5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to