__name__ on new-style classes
Michael Hudson
mwh at python.net
Mon Apr 1 12:19:11 EST 2002
Guido van Rossum <guido at python.org> writes:
> "Gonçalo Rodrigues" wrote:
> >
> > One can change the name of a classic class but not of a new-style one
> > (see below for example). Is this a bug or a feature, and if the latter
> > is there any reason for the change?
>
> It's a feature. The reason for the change is that I've never seen an
> example of a use for it (as opposed to changing an instance's __class__).
> If you have one, let us know.
I've done it, in code that went like:
def wrap(klass):
class Wrapped(klass):
... stuff ...
Wrapped.__name__ = 'Wrapped(%s.%s)'%(klass.__module__.__name__,
klass.__name)
return Wrapped
It makes for slightly better error messages.
Cheers,
M.
More information about the Python-list
mailing list