Skip to content

Add Python3 support #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,37 +1,41 @@
import inspect,dis
import sys
import dis

def expecting():
"""Return how many values the caller is expecting"""
f = inspect.currentframe()
f = sys._getframe(-1)
f = f.f_back.f_back
c = f.f_code
i = f.f_lasti
bytecode = c.co_code
instruction = ord(bytecode[i+3])
i = f.f_lasti + 2
if sys.version_info.major<3:
i += 1
bytecode = c.co_code.decode("latin-1")
instruction = ord(bytecode[i])
if instruction == dis.opmap['UNPACK_SEQUENCE']:
howmany = ord(bytecode[i+4])
howmany = ord(bytecode[i+1])
return howmany
elif instruction == dis.opmap['POP_TOP']:
return 0
return 1

def cleverfunc():
howmany = expecting()
if howmany == 0:
print "return value discarded"
if howmany == 2:
return 1,2
elif howmany == 3:
return 1,2,3
return 1
if __name__ == '__main__':
def cleverfunc():
howmany = expecting()
if howmany == 0:
print "return value discarded"
if howmany == 2:
return 1,2
elif howmany == 3:
return 1,2,3
return 1

def test():
cleverfunc()
x = cleverfunc()
print x
x,y = cleverfunc()
print x,y
x,y,z = cleverfunc()
print x,y,z
def test():
cleverfunc()
x = cleverfunc()
print(x)
x,y = cleverfunc()
print(x,y)
x,y,z = cleverfunc()
print(x,y,z)

test()
test()