That's a good point. Yes I agree, that solution is good (with the extra
None param in getattr of course). I would also do an explicit check for
None like this:

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

I'm sorry I brought this up. It's too nitpicky to waste too much time on
it. The original solution is fine as well.

~ Daniel


-----Original Message-----
From: Gustavo Niemeyer

> 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)


_________________________

TCW Computer Systems has two locations to serve you:
254 S. Esbenshade Rd, Manheim, PA 
1920 Lincoln Highway East, Lancaster, PA
Phone: (717) 653-2700 for both locations
_________________________

** CONFIDENTIAL **

This email communication is intended only for the one to whom it is addressed, 
and may be privileged, confidential and exempt from disclosure.
If you are not that addressee or responsible for delivery to the addressee, any 
dissemination of this communication is prohibited. If you received this email 
in error please reply to the sender. Thank you.




-------------------------------------------------------
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&kid0709&bid&3057&dat1642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to