On 10/17/2016 08:38 AM, Seth P wrote:
On Sunday, October 16, 2016 at 10:09:00 AM UTC-4, Mike Bayer wrote:



    The simplest way is probably to set the creation order of the column to
    be at the top:

    col = Column(...)
    col._creation_order = -10


Great. I will use _creation_order. Thanks.

By the way, in view of PEP 520
(https://docs.python.org/3.6/whatsnew/3.6.html#whatsnew-deforder), in
Python 3.6 will delcared_attr columns appear in their order of
definition among all columns rather than after all explicitly defined
columns?


the _creation_order is set based on a global counter regarding when the Column object was constructed. That will override any ordering that comes in from the way the attributes are visited in the class definition.

It is likely possible to just use __prepare__ in any Python 3 right now to ensure elements are ordered and to override _creation_order in that way, since you can make your own declarative metaclass. The only part that is not doable on the outside is for columns that come out of a declared_attr callable, and the internals of declarative would likely need many changes in order for this to be fully feasible.

However, I don't see how the ordered attributes fixes anything in terms of mixins. If a mixin wants its columns at the beginning, or the end, all of that can be upended by the presence of other mixins and those mixins are necessarily traversed in __mro__ order. It would be awkward to link __mro__ to declared attribute order to the order the expressions that work out to be Column objects go into a Table. IMO it is a lot easier for a mixin or whatever to simply set "Column(... sort_order=-1000)" to deal with simple aesthetic concerns such as these.






However, proposal is to allow the concept of _creation_order to be some public thing such as sort_key. With that, it will be feasible in any Python 3 to build a new metaclass that makes use of __prepare__ to send out an OrderedDict, and then sets up _creation_order on the



--
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 sqlalchemy+unsubscr...@googlegroups.com
<mailto:sqlalchemy+unsubscr...@googlegroups.com>.
To post to this group, send email to sqlalchemy@googlegroups.com
<mailto:sqlalchemy@googlegroups.com>.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

--
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to