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.<br><br>--Guido<br><br><div class="gmail_quote">
On Thu, Jul 4, 2013 at 9:42 AM, Chris Withers <span dir="ltr"><<a href="mailto:chris@simplistix.co.uk" target="_blank">chris@simplistix.co.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Guido,<br>
<br>
I've bumped into this a couple of times.<br>
<br>
First time was when I wanted to know whether what I had was a classmethod, staticmethod or normal method here:<br>
<br>
<a href="https://github.com/Simplistix/testfixtures/blob/master/testfixtures/replace.py#L59" target="_blank">https://github.com/Simplistix/<u></u>testfixtures/blob/master/<u></u>testfixtures/replace.py#L59</a><br>
<br>
This resulted in having to trawl through __dict__ here:<br>
<br>
<a href="https://github.com/Simplistix/testfixtures/blob/master/testfixtures/resolve.py#L17" target="_blank">https://github.com/Simplistix/<u></u>testfixtures/blob/master/<u></u>testfixtures/resolve.py#L17</a><br>
<br>
...rather than just using getattr.<br>
<br>
I bumped into it again, yesterday, trying to add support for classes to this lightweight dependency injection framework I'm developing:<br>
<br>
<a href="https://github.com/Simplistix/mush/blob/master/tests/test_runner.py#L189" target="_blank">https://github.com/Simplistix/<u></u>mush/blob/master/tests/test_<u></u>runner.py#L189</a><br>
<br>
Here's my local copy of that test:<br>
<br>
<a href="https://gist.github.com/cjw296/db64279c69cdc0c5e112" target="_blank">https://gist.github.com/<u></u>cjw296/db64279c69cdc0c5e112</a><br>
<br>
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:<br>
<br>
<a href="https://gist.github.com/cjw296/db64279c69cdc0c5e112#file-gistfile1-txt-L40" target="_blank">https://gist.github.com/<u></u>cjw296/db64279c69cdc0c5e112#<u></u>file-gistfile1-txt-L40</a><br>
<br>
runner = Runner(T0, C1.meth, C2.meth1, C2.meth2)<br>
<br>
...but if I do that, how can the runner know that what it gets for its second argument is a class method of C1?<br>
(which is this case means that it should do C1().meth() rather than C1.meth())<br>
<br>
cheers,<br>
<br>
Chris<div class="im"><br>
<br>
On 04/07/2013 17:25, Guido van Rossum wrote:<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
Chris, what do you want to do with the knowledge you are seeking?<br>
<br>
--Guido van Rossum (sent from Android phone)<br>
<br>
On Jul 4, 2013 4:28 AM, "Chris Withers" <<a href="mailto:chris@simplistix.co.uk" target="_blank">chris@simplistix.co.uk</a><br></div><div class="im">
<mailto:<a href="mailto:chris@simplistix.co.uk" target="_blank">chris@simplistix.co.uk</a><u></u>>> wrote:<br>
<br>
Hi All,<br>
<br>
In Python 2, I can figure out whether I have a method or a function,<br>
and, more importantly, for an unbound method, I can figure out what<br>
class the method belongs to:<br>
<br>
>>> class MyClass(object):<br>
... def method(self): pass<br>
...<br>
>>> MyClass.method<br>
<unbound method MyClass.method><br>
>>> MyClass.method.im_class<br>
<class '__main__.MyClass'><br>
<br>
There doesn't appear to be any way in Python 3 to do this, which is<br>
a little surprising and frustrating...<br>
<br>
What am I missing here?<br>
<br>
Chris<br>
<br>
--<br>
Simplistix - Content Management, Batch Processing & Python Consulting<br>
- <a href="http://www.simplistix.co.uk" target="_blank">http://www.simplistix.co.uk</a><br></div>
______________________________<u></u>___________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org" target="_blank">Python-Dev@python.org</a> <mailto:<a href="mailto:Python-Dev@python.org" target="_blank">Python-Dev@python.org</a>><br>
<a href="http://mail.python.org/__mailman/listinfo/python-dev" target="_blank">http://mail.python.org/__<u></u>mailman/listinfo/python-dev</a><br>
<<a href="http://mail.python.org/mailman/listinfo/python-dev" target="_blank">http://mail.python.org/<u></u>mailman/listinfo/python-dev</a>><br>
Unsubscribe:<br>
<a href="http://mail.python.org/__mailman/options/python-dev/__guido%40python.org" target="_blank">http://mail.python.org/__<u></u>mailman/options/python-dev/__<u></u>guido%40python.org</a><br>
<<a href="http://mail.python.org/mailman/options/python-dev/guido%40python.org" target="_blank">http://mail.python.org/<u></u>mailman/options/python-dev/<u></u>guido%40python.org</a>><br>
<br>
<br>
______________________________<u></u>______________________________<u></u>__________<br>
This email has been scanned by the Symantec Email Security.cloud service.<br>
For more information please visit <a href="http://www.symanteccloud.com" target="_blank">http://www.symanteccloud.com</a><br>
______________________________<u></u>______________________________<u></u>__________<br>
</blockquote><div class="HOEnZb"><div class="h5">
<br>
-- <br>
Simplistix - Content Management, Batch Processing & Python Consulting<br>
- <a href="http://www.simplistix.co.uk" target="_blank">http://www.simplistix.co.uk</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>--Guido van Rossum (<a href="http://python.org/~guido">python.org/~guido</a>)