> Right? Yes, that's fine. That (the first version) will work with
> either classmethod or instance method. I don't see much use in an
> instance method ATM, but you're right why not allow it? It will allow
> (tempt?) people to do things they shouldn't do, but hey this is Python
> and we're consenting adults...

We have a use for it, as I've presented before.

> It will be important to distinguish __session__ and _sa_session_id when 
> this is documented (if it ever is documented).
> 
> Oh, and use a try/except block rather than hasattr. It's more pythonic... 
> So with all those suggestions this is what we end up with:

That's going to make attribute errors inside the method implementation
hard to debug.  The way I usually code it is with getattr:

def default_session(obj=None):
    default_session = getattr(obj, "__default_session__")
    if default_session:
        return default_session()
    else:
        return _default_session(obj=obj)

-- 
Gustavo Niemeyer
http://niemeyer.net


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to