[Python-Dev] lament for the demise of unbound methods
"Martin v. Löwis"
martin at v.loewis.de
Fri Jul 5 12:26:06 CEST 2013
Am 04.07.13 18:42, schrieb Chris Withers:
> Hi Guido,
>
> I've bumped into this a couple of times.
>
> First time was when I wanted to know whether what I had was a
> classmethod, staticmethod or normal method here:
>
> https://github.com/Simplistix/testfixtures/blob/master/testfixtures/replace.py#L59
>
>
> This resulted in having to trawl through __dict__ here:
>
> https://github.com/Simplistix/testfixtures/blob/master/testfixtures/resolve.py#L17
You could use __getattribute__ instead:
>>> class A:
... @staticmethod
... def s():
... pass
... @classmethod
... def c(cl):
... pass
... def r(self):
... pass
...
>>> A.__getattribute__(A,'s')
<staticmethod object at 0x100937828>
>>> A.__getattribute__(A,'c')
<classmethod object at 0x100937860>
>>> A.__getattribute__(A,'r')
<function A.r at 0x100938378>
Regards,
Martin
More information about the Python-Dev
mailing list