[Python-Dev] Py2.5 release schedule (original) (raw)
"Martin v. Löwis" martin at v.loewis.de
Sun Jul 30 23:34:30 CEST 2006
- Previous message: [Python-Dev] Py2.5 release schedule
- Next message: [Python-Dev] Py2.5 release schedule
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Fred L. Drake, Jr. schrieb:
On Sunday 30 July 2006 15:44, Barry Warsaw wrote: > if isinstance(obj, ClassType) or isinstance(obj, type(type))
Looks like you've got a possible name clash in the second isinstance. ;-)
Nah, that's rather an entry to the obfuscated Python contest. The two occurrences of type really mean to refer to the same thing; this is the test whether obj is a new-style class.
Normally, you would write isinstance(obj, type), but that gives a TypeError in 2.1 (isinstance() arg 2 must be a class or type). In 2.1, type(type) is FunctionType, so the test should fail (in the context, as obj ought to be a string, an exception object, or an exception type). In 2.2 and later, we have
type(type) is type 1 # sometimes True instead
I think I would have rewritten as
try:
Instantiate it if possible and necessary
exc = exc() except AttributeError: # no call; it's already an object pass
(assuming that the mailman exceptions don't have call) or as
if not isinstance(exc, Exception): exc = exc()
(assuming that string exceptions are gone, but the code below already assumes that exc should be an object that supports exc.reason_notice())
Regards, Martin
- Previous message: [Python-Dev] Py2.5 release schedule
- Next message: [Python-Dev] Py2.5 release schedule
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]