"my brain hurts" or is isinstance broken?
Robert Kuzelj
robert_kuzelj at yahoo.com
Wed Jul 3 15:43:50 EDT 2002
hi jonathan,
> 1. Reverse the test and check to see if something is an instance of 'type'
> of 'types.ClassType', i.e., a new-style class or an old-style class.
>
> if isinstance(source, type) or isinstance(source, types.ClassType)
> return source()
> else:
> return copy.copy( source )
that is exactly what i did. but i dont like this solution cause
as i told before it is rather implicit than explicit.
> 2. If you know that the instances you are creating will not have '__call__'
> methods, then you can differentiate classes and instances by the fact
> that classes are callable:
>
> if callable( source ):
> return source()
> else:
> return copy.copy( source )
>
> This works equally well for old- and new-style classes. Conveniently it
> also works functions that create objects and callable instances
> masquerading as classes or functions that create objects (hoo hah).
cant do that since i have absolutly no control of what is being given
to me.
> Oh, you can tell us. No matter what crimes your contemplating, you can take
> comfort in the fact that they can probably be made more horrifying with
> metaclasses ;-)
;-) dont despair! i WILL use metaclasses on a later stage of the project.
ciao robertj
More information about the Python-list
mailing list