Re: [Python-Dev] lament for the demise of unbound methods

2013-07-06 Thread Chris Withers
On 05/07/2013 11:26, "Martin v. Löwis" wrote: ... A.__getattribute__(A,'s') A.__getattribute__(A,'c') A.__getattribute__(A,'r') Okay, but with this line: found = found.__getattribute__(found, n) I get a tonne of failures like this: File "testfixtures.tests.test_replacer.TestRe

Re: [Python-Dev] lament for the demise of unbound methods

2013-07-06 Thread Raymond Hettinger
On Jul 4, 2013, at 2:34 AM, Brett Cannon wrote: > The loss of the ability to figure out the class from an unbound method seems > quite an annoying step back from an introspection point of view. > > It's only annoying if you take the perspective that methods are somehow > special compared to f

Re: [Python-Dev] lament for the demise of unbound methods

2013-07-06 Thread Nick Coghlan
On 6 Jul 2013 22:52, "Michael Foord" wrote: > > > On 5 Jul 2013, at 12:26, Łukasz Langa wrote: > > > On 5 lip 2013, at 12:07, Martin v. Löwis wrote: > > > >> I wonder why you need to figure out the signatures in advance. > >> Can you just wait until the function is actually used, and then > >> p

Re: [Python-Dev] lament for the demise of unbound methods

2013-07-06 Thread Michael Foord
On 5 Jul 2013, at 12:26, Łukasz Langa wrote: > On 5 lip 2013, at 12:07, Martin v. Löwis wrote: > >> I wonder why you need to figure out the signatures in advance. >> Can you just wait until the function is actually used, and then >> process the parameters as you get them? >> > > My guess is

Re: [Python-Dev] lament for the demise of unbound methods

2013-07-06 Thread Michael Foord
On 5 Jul 2013, at 12:07, "Martin v. Löwis" wrote: > Am 05.07.13 11:23, schrieb Michael Foord: >> I've also lamented the death of bound methods in Python 3 for mock >> "autospeccing". Autospec introspects objects and provides mock >> objects with the same attributes - and with the same method >>

Re: [Python-Dev] lament for the demise of unbound methods

2013-07-05 Thread Martin v. Löwis
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.

Re: [Python-Dev] lament for the demise of unbound methods

2013-07-05 Thread Łukasz Langa
On 5 lip 2013, at 12:07, Martin v. Löwis wrote: > I wonder why you need to figure out the signatures in advance. > Can you just wait until the function is actually used, and then > process the parameters as you get them? > My guess is that Michael's design lets mock objects be introspected as w

Re: [Python-Dev] lament for the demise of unbound methods

2013-07-05 Thread Martin v. Löwis
Am 05.07.13 11:23, schrieb Michael Foord: > I've also lamented the death of bound methods in Python 3 for mock > "autospeccing". Autospec introspects objects and provides mock > objects with the same attributes - and with the same method > signatures. I wonder why you need to figure out the signat

Re: [Python-Dev] lament for the demise of unbound methods

2013-07-05 Thread Michael Foord
On 4 Jul 2013, at 19:00, Guido van Rossum wrote: > Thanks for the code pointers. So it's all about monkeypatching. :-) I have > only a little sympathy, as there still seems to be a way to do this, it's > just less convenient. Too bad. > I've also lamented the death of bound methods in Pytho

Re: [Python-Dev] lament for the demise of unbound methods

2013-07-04 Thread Chris Withers
On 04/07/2013 20:50, Benjamin Peterson wrote: 2013/7/4 Eric Snow : You could always monkeypatch builtins.__build_class__ to add an attribute to every "unbound method" pointing to the class. I would not reccomend that. __build_class__ is very internal and it's contract may change between versi

Re: [Python-Dev] lament for the demise of unbound methods

2013-07-04 Thread Benjamin Peterson
2013/7/4 Eric Snow : > > On Thu, Jul 4, 2013 at 5:21 AM, Chris Withers > wrote: >> >> Hi All, >> >> In Python 2, I can figure out whether I have a method or a function, and, >> more importantly, for an unbound method, I can figure out what class the >> method belongs to: >> >> >>> class MyClass(ob

Re: [Python-Dev] lament for the demise of unbound methods

2013-07-04 Thread Eric Snow
On Thu, Jul 4, 2013 at 5:21 AM, Chris Withers wrote: > Hi All, > > In Python 2, I can figure out whether I have a method or a function, and, > more importantly, for an unbound method, I can figure out what class the > method belongs to: > > >>> class MyClass(object): > ... def method(self): pass

Re: [Python-Dev] lament for the demise of unbound methods

2013-07-04 Thread Chris Withers
On 04/07/2013 18:00, Guido van Rossum wrote: Thanks for the code pointers. So it's all about monkeypatching. :-) Well, that's the testfixtures use case, but for mush it's about figuring out whether you need to instantiate a class before calling a callable. MyClass.a_method is a bit like a fu

Re: [Python-Dev] lament for the demise of unbound methods

2013-07-04 Thread Guido van Rossum
Thanks for the code pointers. So it's all about monkeypatching. :-) I have only a little sympathy, as there still seems to be a way to do this, it's just less convenient. Too bad. --Guido On Thu, Jul 4, 2013 at 9:42 AM, Chris Withers wrote: > Hi Guido, > > I've bumped into this a couple of times

Re: [Python-Dev] lament for the demise of unbound methods

2013-07-04 Thread 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

Re: [Python-Dev] lament for the demise of unbound methods

2013-07-04 Thread Guido van Rossum
Chris, what do you want to do with the knowledge you are seeking? --Guido van Rossum (sent from Android phone) On Jul 4, 2013 4:28 AM, "Chris Withers" wrote: > Hi All, > > In Python 2, I can figure out whether I have a method or a function, and, > more importantly, for an unbound method, I can f

Re: [Python-Dev] lament for the demise of unbound methods

2013-07-04 Thread Victor Stinner
2013/7/4 Chris Withers : > That doesn't seem helpful as a sensible way to get back to the class object: > >>> globals()[MyClass.method.__qualname__.split('.')[0]] > globals() can only be used if MyClass is in the same module. Otherwise, you a more complex function: --- import types d

Re: [Python-Dev] lament for the demise of unbound methods

2013-07-04 Thread Brett Cannon
On Thu, Jul 4, 2013 at 8:13 AM, Chris Withers wrote: > On 04/07/2013 12:59, Christian Heimes wrote: > >> Am 04.07.2013 13:21, schrieb Chris Withers: >> >>> There doesn't appear to be any way in Python 3 to do this, which is a >>> little surprising and frustrating... >>> >>> What am I missing here?

Re: [Python-Dev] lament for the demise of unbound methods

2013-07-04 Thread Chris Withers
On 04/07/2013 12:55, Ronald Oussoren wrote: You can find the fully qualified name of the method with the qualname attribute: class A: ...def method(self): pass ... A.method.__qualname__ 'A.method' That doesn't seem helpful as a sensible way to get back to the class object: >> globals

Re: [Python-Dev] lament for the demise of unbound methods

2013-07-04 Thread Chris Withers
On 04/07/2013 12:59, Christian Heimes wrote: Am 04.07.2013 13:21, schrieb Chris Withers: There doesn't appear to be any way in Python 3 to do this, which is a little surprising and frustrating... What am I missing here? I removed unbound methods almost six years ago: http://hg.python.org/cpy

Re: [Python-Dev] lament for the demise of unbound methods

2013-07-04 Thread Christian Heimes
Am 04.07.2013 13:21, schrieb Chris Withers: > There doesn't appear to be any way in Python 3 to do this, which is a > little surprising and frustrating... > > What am I missing here? I removed unbound methods almost six years ago: http://hg.python.org/cpython/rev/48af6375207e Christian

Re: [Python-Dev] lament for the demise of unbound methods

2013-07-04 Thread Ronald Oussoren
On 4 Jul, 2013, at 13:21, Chris Withers wrote: > Hi All, > > In Python 2, I can figure out whether I have a method or a function, and, > more importantly, for an unbound method, I can figure out what class the > method belongs to: > > >>> class MyClass(object): > ... def method(self): pass

[Python-Dev] lament for the demise of unbound methods

2013-07-04 Thread Chris Withers
Hi All, In Python 2, I can figure out whether I have a method or a function, and, more importantly, for an unbound method, I can figure out what class the method belongs to: >>> class MyClass(object): ... def method(self): pass ... >>> MyClass.method >>> MyClass.method.im_class There doe