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

Guido van Rossum guido at python.org
Thu Jul 4 19:00:46 CEST 2013


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 <chris at simplistix.co.uk>wrote:

> 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<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<https://github.com/Simplistix/testfixtures/blob/master/testfixtures/resolve.py#L17>
>
> ...rather than just using getattr.
>
> I bumped into it again, yesterday, trying to add support for classes to
> this lightweight dependency injection framework I'm developing:
>
> https://github.com/Simplistix/**mush/blob/master/tests/test_**
> runner.py#L189<https://github.com/Simplistix/mush/blob/master/tests/test_runner.py#L189>
>
> Here's my local copy of that test:
>
> https://gist.github.com/**cjw296/db64279c69cdc0c5e112<https://gist.github.com/cjw296/db64279c69cdc0c5e112>
>
> The workaround I was playing with this morning is a wrapper so that I know
> I have a class method, although what I really want to write at this line is:
>
> https://gist.github.com/**cjw296/db64279c69cdc0c5e112#**
> file-gistfile1-txt-L40<https://gist.github.com/cjw296/db64279c69cdc0c5e112#file-gistfile1-txt-L40>
>
> runner = Runner(T0, C1.meth, C2.meth1, C2.meth2)
>
> ...but if I do that, how can the runner know that what it gets for its
> second argument is a class method of C1?
> (which is this case means that it should do C1().meth() rather than
> C1.meth())
>
> cheers,
>
> Chris
>
>
> On 04/07/2013 17:25, Guido van Rossum wrote:
>
>> 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" <chris at simplistix.co.uk
>> <mailto:chris at simplistix.co.uk**>> 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
>>     ...
>>      >>> MyClass.method
>>     <unbound method MyClass.method>
>>      >>> MyClass.method.im_class
>>     <class '__main__.MyClass'>
>>
>>     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?
>>
>>     Chris
>>
>>     --
>>     Simplistix - Content Management, Batch Processing & Python Consulting
>>                  - http://www.simplistix.co.uk
>>     ______________________________**___________________
>>     Python-Dev mailing list
>>     Python-Dev at python.org <mailto:Python-Dev at python.org>
>>     http://mail.python.org/__**mailman/listinfo/python-dev<http://mail.python.org/__mailman/listinfo/python-dev>
>>     <http://mail.python.org/**mailman/listinfo/python-dev<http://mail.python.org/mailman/listinfo/python-dev>
>> >
>>     Unsubscribe:
>>     http://mail.python.org/__**mailman/options/python-dev/__**
>> guido%40python.org<http://mail.python.org/__mailman/options/python-dev/__guido%40python.org>
>>     <http://mail.python.org/**mailman/options/python-dev/**
>> guido%40python.org<http://mail.python.org/mailman/options/python-dev/guido%40python.org>
>> >
>>
>>
>> ______________________________**______________________________**
>> __________
>> This email has been scanned by the Symantec Email Security.cloud service.
>> For more information please visit http://www.symanteccloud.com
>> ______________________________**______________________________**
>> __________
>>
>
> --
> Simplistix - Content Management, Batch Processing & Python Consulting
>             - http://www.simplistix.co.uk
>



-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20130704/6af3f21d/attachment.html>


More information about the Python-Dev mailing list