introspection question: get return type

Diez B. Roggisch deets at nospam.web.de
Thu May 14 09:07:24 EDT 2009


Diez B. Roggisch wrote:

> flamz3d at gmail.com wrote:
> 
>> Hello,
>> I am wondering if it's possible to get the return value of a method
>> *without* calling it using introspection?
> 
> Nope. All that's possible to see if there is a implicit or explicit return
> through dis.disassemble - if you find "LOAD_CONST None" before any
> return-statement, you know that you don't anything else.

Gosh, this is barely intelligible...

What I wanted to say is that you can check if a function only returns
constant values, which most of the time will be implicit "return None"
statements, as in this:

def foo():
    a = 10

dis.disassemble(foo.func_code)
...
  2           0 LOAD_CONST               0 (None)
              3 RETURN_VALUE
Diez



More information about the Python-list mailing list