[Python-Dev] Re: [Python-checkins] python/dist/src/Lib pprint.py, 1.24, 1.25

Samuele Pedroni pedronis@bluewin.ch
Sun, 08 Jun 2003 18:57:01 +0200


At 18:09 08.06.2003 +0200, Gerrit Holl wrote:
>Hi,
>
>Alex Martelli wrote:
> > >     if issubclass(typ, dict) and type(typ.__repr__) is 
> type(dict.__repr__):
> > >         # do stuff
> >
> > Aren't the calls to type() here wrong?  It seems to me that what you want
> > to check is just whether typ.__repr__ is dict.__repr__, not if the 
> types of
> > the two bound methods are the same.
>
>I was confused: I thought methods were dynamically created, but that is
>only true for bound methods, not for unbound methods. typ.__repr__ is
>dict.__repr__ is correct indeed.
>
>yours,
>Gerrit.

no it's true also for unbound methods but dict.__repr__ isn't either:

 >>> class C(object):
...   def f(self): pass
...
 >>> C.f is C.f
0
 >>> C.f
<unbound method C.f>
 >>> dict.__repr__
<slot wrapper '__repr__' of 'dict' objects>
 >>>

the problem is that the nature of dict.__repr__ is kind of an 
implementation  detail.

regards.