A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2013-July/127181.html below:

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

[Python-Dev] lament for the demise of unbound methodsChris Withers chris at simplistix.co.uk
Thu Jul 4 18:42:07 CEST 2013
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

...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

Here's my local copy of that test:

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

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>
>     Unsubscribe:
>     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
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4