On 21.05.12 07:52, Stefano Taschini wrote:
On 21 May 2012 03:36, Guido van Rossum <gu...@python.org <mailto:gu...@python.org>> wrote:

    [...]

    I have to agree with Christian that inspect.py is full of hacks and
    heuristics that would be fine in a module that's part of a user's app
    or even in a library, but stand out as brittle or outright unreliable
    in a stdlib module. Basically, you can't trust that inspect.py will
    work. I've seen various occasions (sorry, can't remember details)
    where some function in it outright crashed when given a slightly
    unusual (but not unreasonable) argument. It might be a nice project
    for a new contributor to improve this situation.
    [...]


An example that crashes is

     >>>  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)
     >>>  inspect.getargspec(f)

See http://bugs.python.org/issue14611 . I did submit a patch, a few weeks ago.

Nice finding, not related to dir() usage but very useful to know.
I looked over test_inspect.py a bit, which is quite big and has many
tests, although very little references to reported bugs, and this
opcode combination was obviously missing in the test cases.

Did not find your patch yet (no time), but hope you added an extra
testcase with explicit reference to the bug reported.

inspect is very nice and useful in many cases, but sometimes not. Instead
of using things like currentframe() I have a look and write my own version
because the convenience is too little compared to an extra import and
dependency. And although currentframe() is mentioned in test_inspect,
I cannot find any direct testcase for it that really calls this function.

Admittedly a trivial case, but it is one reason, besides dissed dir() usage,
that makes me think of 'suspect' ;-)

Instead, I'd love to use inspect as the basis to write reliable, portable
code, because its abstraction hides implementation details nicely.
I think we have reached when things like sys._getframe() are declared
as deprecated.

""" This is no longer recommended to use. Use inspect.currentframe instead """

cheers - chris

--
Christian Tismer             :^)<mailto:tis...@stackless.com>
tismerysoft GmbH             :     Have a break! Take a ride on Python's
Karl-Liebknecht-Str. 121     :    *Starship* http://starship.python.net/
14482 Potsdam                :     PGP key ->  http://pgp.uni-mainz.de
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?   http://www.stackless.com/

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to