Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ul> <li><code>print result</code> in my own class always prints None.</li> </ul> <p>This is because constructor doesn't return anything :)</p> <ul> <li>Why is the metaclass using <code>__init__</code> and not <code>__new__</code></li> </ul> <p>I think it is because SQLAlchemy needs to store a reference of cls into the declarative class registry. In <code>__new__</code>, the class doesn't exist yet (see <a href="https://stackoverflow.com/a/1840466">https://stackoverflow.com/a/1840466</a>).</p> <p>When I subclassed <code>DeclarativeMeta</code>, I actually did everything in <code>__init__</code> following SQLAlchemy's code. In retrospect after reading your question, my code should use <code>__new__</code> instead.</p> <ul> <li><code>declarative_base</code> returns an instance of this class. Shouldn't it return a class having an attribute <code>__metaclass__</code> having <code>MyDeclarativeMeta</code> as value?</li> </ul> <p>I think Ben explained this very well. Anyway, if you want (not recommended), you can skip calling <code>declarative_base()</code> and create your own Base class, e.g.</p> <pre><code># Almost the same as: # Base = declarative_base(cls=Entity, name='Base', metaclass=MyDeclarativeMeta) # minus the _declarative_constructor. class Base(Entity): __metaclass__ = MyDeclarativeMeta _decl_class_registry = dict() metadata = MetaData() </code></pre> <p>In this case, the <code>__metaclass__</code> attribute will be there. I actually created my Base class like this to help PyCharm getting the auto-completion for things defined in <code>Entity</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload