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
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4