<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
On 21.05.12 07:52, Stefano Taschini wrote:
<blockquote
cite="mid:CAPdNJuAFAY48P63ZjO4LaoVU0RoRs=m081yzc8UiFCr6EoTj5g@mail.gmail.com"
type="cite">
<div class="gmail_quote">On 21 May 2012 03:36, Guido van Rossum <span
dir="ltr">&lt;<a moz-do-not-send="true"
href="mailto:guido@python.org" target="_blank">guido@python.org</a>&gt;</span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">[...]<br>
<br>
</div>
I have to agree with Christian that inspect.py is full of
hacks and<br>
heuristics that would be fine in a module that's part of a
user's app<br>
or even in a library, but stand out as brittle or outright
unreliable<br>
in a stdlib module. Basically, you can't trust that inspect.py
will<br>
work. I've seen various occasions (sorry, can't remember
details)<br>
where some function in it outright crashed when given a
slightly<br>
unusual (but not unreasonable) argument. It might be a nice
project<br>
for a new contributor to improve this situation.<br>
<span class="HOEnZb"><font color="#888888">[...]</font></span><br>
</blockquote>
</div>
<br>
An example that crashes is <br>
<br>
<pre> &gt;&gt;&gt; def f(l, (x, y)):
... sup = max(u*x + v*y for u, v in l)
... return ((u, v) for u, v in l if u*x + v*y == sup)
&gt;&gt;&gt; inspect.getargspec(f)
</pre>
<br>
See <a moz-do-not-send="true"
href="http://bugs.python.org/issue14611">http://bugs.python.org/issue14611</a>
. I did submit a patch, a few weeks ago.<br>
</blockquote>
<br>
Nice finding, not related to dir() usage but very useful to know.<br>
I looked over test_inspect.py a bit, which is quite big and has many<br>
tests, although very little references to reported bugs, and this<br>
opcode combination was obviously missing in the test cases.<br>
<br>
Did not find your patch yet (no time), but hope you added an extra<br>
testcase with explicit reference to the bug reported.<br>
<br>
inspect is very nice and useful in many cases, but sometimes not.
Instead<br>
of using things like currentframe() I have a look and write my own
version<br>
because the convenience is too little compared to an extra import
and<br>
dependency. And although currentframe() is mentioned in
test_inspect,<br>
I cannot find any direct testcase for it that really calls this
function.<br>
<br>
Admittedly a trivial case, but it is one reason, besides dissed
dir() usage,<br>
that makes me think of 'suspect' ;-)<br>
<br>
Instead, I'd love to use inspect as the basis to write reliable,
portable<br>
code, because its abstraction hides implementation details nicely.<br>
I think we have reached when things like sys._getframe() are
declared<br>
as deprecated.<br>
<br>
""" This is no longer recommended to use. Use inspect.currentframe
instead """<br>
<br>
cheers - chris<br>
<pre class="moz-signature" cols="72">--
Christian Tismer :^) <a class="moz-txt-link-rfc2396E" href="mailto:tismer@stackless.com">&lt;mailto:tismer@stackless.com&gt;</a>
tismerysoft GmbH : Have a break! Take a ride on Python's
Karl-Liebknecht-Str. 121 : *Starship* <a class="moz-txt-link-freetext" href="http://starship.python.net/">http://starship.python.net/</a>
14482 Potsdam : PGP key -&gt; <a class="moz-txt-link-freetext" href="http://pgp.uni-mainz.de">http://pgp.uni-mainz.de</a>
work +49 173 24 18 776 mobile +49 173 24 18 776 fax n.a.
PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04
whom do you want to sponsor today? <a class="moz-txt-link-freetext" href="http://www.stackless.com/">http://www.stackless.com/</a></pre>
</body>
</html>

AltStyle によって変換されたページ (->オリジナル) /