Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(49952)

Side by Side Diff: Lib/test/test_dis.py

Issue 27095: Simplify MAKE_FUNCTION
Patch Set: Created 3 years, 3 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Minimal tests for dis module 1 # Minimal tests for dis module
2 2
3 from test.support import captured_stdout 3 from test.support import captured_stdout
4 from test.bytecode_helper import BytecodeTestCase 4 from test.bytecode_helper import BytecodeTestCase
5 import difflib 5 import difflib
6 import unittest 6 import unittest
7 import sys 7 import sys
8 import dis 8 import dis
9 import io 9 import io
10 import re 10 import re
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 #_instructions = dis.get_instructions(outer()(), first_line=expected_inner_line) 642 #_instructions = dis.get_instructions(outer()(), first_line=expected_inner_line)
643 #print('expected_opinfo_inner = [\n ', 643 #print('expected_opinfo_inner = [\n ',
644 #',\n '.join(map(str, _instructions)), ',\n]', sep='') 644 #',\n '.join(map(str, _instructions)), ',\n]', sep='')
645 #_instructions = dis.get_instructions(jumpy, first_line=expected_jumpy_line) 645 #_instructions = dis.get_instructions(jumpy, first_line=expected_jumpy_line)
646 #print('expected_opinfo_jumpy = [\n ', 646 #print('expected_opinfo_jumpy = [\n ',
647 #',\n '.join(map(str, _instructions)), ',\n]', sep='') 647 #',\n '.join(map(str, _instructions)), ',\n]', sep='')
648 648
649 649
650 Instruction = dis.Instruction 650 Instruction = dis.Instruction
651 expected_opinfo_outer = [ 651 expected_opinfo_outer = [
652 Instruction(opname='LOAD_CONST', opcode=100, arg=1, argval=3, argrepr='3', off set=0, starts_line=2, is_jump_target=False), 652 Instruction(opname='LOAD_CONST', opcode=100, arg=8, argval=(3, 4), argrepr='(3 , 4)', offset=0, starts_line=2, is_jump_target=False),
653 Instruction(opname='LOAD_CONST', opcode=100, arg=2, argval=4, argrepr='4', off set=2, starts_line=None, is_jump_target=False), 653 Instruction(opname='LOAD_CLOSURE', opcode=135, arg=0, argval='a', argrepr='a', offset=2, starts_line=None, is_jump_target=False),
654 Instruction(opname='LOAD_CLOSURE', opcode=135, arg=0, argval='a', argrepr='a', offset=4, starts_line=None, is_jump_target=False), 654 Instruction(opname='LOAD_CLOSURE', opcode=135, arg=1, argval='b', argrepr='b', offset=4, starts_line=None, is_jump_target=False),
655 Instruction(opname='LOAD_CLOSURE', opcode=135, arg=1, argval='b', argrepr='b', offset=6, starts_line=None, is_jump_target=False), 655 Instruction(opname='BUILD_TUPLE', opcode=102, arg=2, argval=2, argrepr='', off set=6, starts_line=None, is_jump_target=False),
656 Instruction(opname='BUILD_TUPLE', opcode=102, arg=2, argval=2, argrepr='', off set=8, starts_line=None, is_jump_target=False), 656 Instruction(opname='LOAD_CONST', opcode=100, arg=3, argval=code_object_f, argr epr=repr(code_object_f), offset=8, starts_line=None, is_jump_target=False),
657 Instruction(opname='LOAD_CONST', opcode=100, arg=3, argval=code_object_f, argr epr=repr(code_object_f), offset=10, starts_line=None, is_jump_target=False), 657 Instruction(opname='LOAD_CONST', opcode=100, arg=4, argval='outer.<locals>.f', argrepr="'outer.<locals>.f'", offset=10, starts_line=None, is_jump_target=False ),
658 Instruction(opname='LOAD_CONST', opcode=100, arg=4, argval='outer.<locals>.f', argrepr="'outer.<locals>.f'", offset=12, starts_line=None, is_jump_target=False ), 658 Instruction(opname='MAKE_FUNCTION', opcode=132, arg=9, argval=9, argrepr='', o ffset=12, starts_line=None, is_jump_target=False),
659 Instruction(opname='MAKE_CLOSURE', opcode=134, arg=2, argval=2, argrepr='', of fset=14, starts_line=None, is_jump_target=False), 659 Instruction(opname='STORE_FAST', opcode=125, arg=2, argval='f', argrepr='f', o ffset=14, starts_line=None, is_jump_target=False),
660 Instruction(opname='STORE_FAST', opcode=125, arg=2, argval='f', argrepr='f', o ffset=16, starts_line=None, is_jump_target=False), 660 Instruction(opname='LOAD_GLOBAL', opcode=116, arg=0, argval='print', argrepr=' print', offset=16, starts_line=7, is_jump_target=False),
661 Instruction(opname='LOAD_GLOBAL', opcode=116, arg=0, argval='print', argrepr=' print', offset=18, starts_line=7, is_jump_target=False), 661 Instruction(opname='LOAD_DEREF', opcode=136, arg=0, argval='a', argrepr='a', o ffset=18, starts_line=None, is_jump_target=False),
662 Instruction(opname='LOAD_DEREF', opcode=136, arg=0, argval='a', argrepr='a', o ffset=20, starts_line=None, is_jump_target=False), 662 Instruction(opname='LOAD_DEREF', opcode=136, arg=1, argval='b', argrepr='b', o ffset=20, starts_line=None, is_jump_target=False),
663 Instruction(opname='LOAD_DEREF', opcode=136, arg=1, argval='b', argrepr='b', o ffset=22, starts_line=None, is_jump_target=False), 663 Instruction(opname='LOAD_CONST', opcode=100, arg=5, argval='', argrepr="''", o ffset=22, starts_line=None, is_jump_target=False),
664 Instruction(opname='LOAD_CONST', opcode=100, arg=5, argval='', argrepr="''", o ffset=24, starts_line=None, is_jump_target=False), 664 Instruction(opname='LOAD_CONST', opcode=100, arg=6, argval=1, argrepr='1', off set=24, starts_line=None, is_jump_target=False),
665 Instruction(opname='LOAD_CONST', opcode=100, arg=6, argval=1, argrepr='1', off set=26, starts_line=None, is_jump_target=False), 665 Instruction(opname='BUILD_LIST', opcode=103, arg=0, argval=0, argrepr='', offs et=26, starts_line=None, is_jump_target=False),
666 Instruction(opname='BUILD_LIST', opcode=103, arg=0, argval=0, argrepr='', offs et=28, starts_line=None, is_jump_target=False), 666 Instruction(opname='BUILD_MAP', opcode=105, arg=0, argval=0, argrepr='', offse t=28, starts_line=None, is_jump_target=False),
667 Instruction(opname='BUILD_MAP', opcode=105, arg=0, argval=0, argrepr='', offse t=30, starts_line=None, is_jump_target=False), 667 Instruction(opname='LOAD_CONST', opcode=100, arg=7, argval='Hello world!', arg repr="'Hello world!'", offset=30, starts_line=None, is_jump_target=False),
668 Instruction(opname='LOAD_CONST', opcode=100, arg=7, argval='Hello world!', arg repr="'Hello world!'", offset=32, starts_line=None, is_jump_target=False), 668 Instruction(opname='CALL_FUNCTION', opcode=131, arg=7, argval=7, argrepr='7 po sitional, 0 keyword pair', offset=32, starts_line=None, is_jump_target=False),
669 Instruction(opname='CALL_FUNCTION', opcode=131, arg=7, argval=7, argrepr='7 po sitional, 0 keyword pair', offset=34, starts_line=None, is_jump_target=False), 669 Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', off set=34, starts_line=None, is_jump_target=False),
670 Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', off set=36, starts_line=None, is_jump_target=False), 670 Instruction(opname='LOAD_FAST', opcode=124, arg=2, argval='f', argrepr='f', of fset=36, starts_line=8, is_jump_target=False),
671 Instruction(opname='LOAD_FAST', opcode=124, arg=2, argval='f', argrepr='f', of fset=38, starts_line=8, is_jump_target=False), 671 Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr=' ', offset=38, starts_line=None, is_jump_target=False),
672 Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr=' ', offset=40, starts_line=None, is_jump_target=False),
673 ] 672 ]
674 673
675 expected_opinfo_f = [ 674 expected_opinfo_f = [
676 Instruction(opname='LOAD_CONST', opcode=100, arg=1, argval=5, argrepr='5', off set=0, starts_line=3, is_jump_target=False), 675 Instruction(opname='LOAD_CONST', opcode=100, arg=5, argval=(5, 6), argrepr='(5 , 6)', offset=0, starts_line=3, is_jump_target=False),
677 Instruction(opname='LOAD_CONST', opcode=100, arg=2, argval=6, argrepr='6', off set=2, starts_line=None, is_jump_target=False), 676 Instruction(opname='LOAD_CLOSURE', opcode=135, arg=2, argval='a', argrepr='a', offset=2, starts_line=None, is_jump_target=False),
678 Instruction(opname='LOAD_CLOSURE', opcode=135, arg=2, argval='a', argrepr='a', offset=4, starts_line=None, is_jump_target=False), 677 Instruction(opname='LOAD_CLOSURE', opcode=135, arg=3, argval='b', argrepr='b', offset=4, starts_line=None, is_jump_target=False),
679 Instruction(opname='LOAD_CLOSURE', opcode=135, arg=3, argval='b', argrepr='b', offset=6, starts_line=None, is_jump_target=False), 678 Instruction(opname='LOAD_CLOSURE', opcode=135, arg=0, argval='c', argrepr='c', offset=6, starts_line=None, is_jump_target=False),
680 Instruction(opname='LOAD_CLOSURE', opcode=135, arg=0, argval='c', argrepr='c', offset=8, starts_line=None, is_jump_target=False), 679 Instruction(opname='LOAD_CLOSURE', opcode=135, arg=1, argval='d', argrepr='d', offset=8, starts_line=None, is_jump_target=False),
681 Instruction(opname='LOAD_CLOSURE', opcode=135, arg=1, argval='d', argrepr='d', offset=10, starts_line=None, is_jump_target=False), 680 Instruction(opname='BUILD_TUPLE', opcode=102, arg=4, argval=4, argrepr='', off set=10, starts_line=None, is_jump_target=False),
682 Instruction(opname='BUILD_TUPLE', opcode=102, arg=4, argval=4, argrepr='', off set=12, starts_line=None, is_jump_target=False), 681 Instruction(opname='LOAD_CONST', opcode=100, arg=3, argval=code_object_inner, argrepr=repr(code_object_inner), offset=12, starts_line=None, is_jump_target=Fal se),
683 Instruction(opname='LOAD_CONST', opcode=100, arg=3, argval=code_object_inner, argrepr=repr(code_object_inner), offset=14, starts_line=None, is_jump_target=Fal se), 682 Instruction(opname='LOAD_CONST', opcode=100, arg=4, argval='outer.<locals>.f.< locals>.inner', argrepr="'outer.<locals>.f.<locals>.inner'", offset=14, starts_l ine=None, is_jump_target=False),
684 Instruction(opname='LOAD_CONST', opcode=100, arg=4, argval='outer.<locals>.f.< locals>.inner', argrepr="'outer.<locals>.f.<locals>.inner'", offset=16, starts_l ine=None, is_jump_target=False), 683 Instruction(opname='MAKE_FUNCTION', opcode=132, arg=9, argval=9, argrepr='', o ffset=16, starts_line=None, is_jump_target=False),
685 Instruction(opname='MAKE_CLOSURE', opcode=134, arg=2, argval=2, argrepr='', of fset=18, starts_line=None, is_jump_target=False), 684 Instruction(opname='STORE_FAST', opcode=125, arg=2, argval='inner', argrepr='i nner', offset=18, starts_line=None, is_jump_target=False),
686 Instruction(opname='STORE_FAST', opcode=125, arg=2, argval='inner', argrepr='i nner', offset=20, starts_line=None, is_jump_target=False), 685 Instruction(opname='LOAD_GLOBAL', opcode=116, arg=0, argval='print', argrepr=' print', offset=20, starts_line=5, is_jump_target=False),
687 Instruction(opname='LOAD_GLOBAL', opcode=116, arg=0, argval='print', argrepr=' print', offset=22, starts_line=5, is_jump_target=False), 686 Instruction(opname='LOAD_DEREF', opcode=136, arg=2, argval='a', argrepr='a', o ffset=22, starts_line=None, is_jump_target=False),
688 Instruction(opname='LOAD_DEREF', opcode=136, arg=2, argval='a', argrepr='a', o ffset=24, starts_line=None, is_jump_target=False), 687 Instruction(opname='LOAD_DEREF', opcode=136, arg=3, argval='b', argrepr='b', o ffset=24, starts_line=None, is_jump_target=False),
689 Instruction(opname='LOAD_DEREF', opcode=136, arg=3, argval='b', argrepr='b', o ffset=26, starts_line=None, is_jump_target=False), 688 Instruction(opname='LOAD_DEREF', opcode=136, arg=0, argval='c', argrepr='c', o ffset=26, starts_line=None, is_jump_target=False),
690 Instruction(opname='LOAD_DEREF', opcode=136, arg=0, argval='c', argrepr='c', o ffset=28, starts_line=None, is_jump_target=False), 689 Instruction(opname='LOAD_DEREF', opcode=136, arg=1, argval='d', argrepr='d', o ffset=28, starts_line=None, is_jump_target=False),
691 Instruction(opname='LOAD_DEREF', opcode=136, arg=1, argval='d', argrepr='d', o ffset=30, starts_line=None, is_jump_target=False), 690 Instruction(opname='CALL_FUNCTION', opcode=131, arg=4, argval=4, argrepr='4 po sitional, 0 keyword pair', offset=30, starts_line=None, is_jump_target=False),
692 Instruction(opname='CALL_FUNCTION', opcode=131, arg=4, argval=4, argrepr='4 po sitional, 0 keyword pair', offset=32, starts_line=None, is_jump_target=False), 691 Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', off set=32, starts_line=None, is_jump_target=False),
693 Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', off set=34, starts_line=None, is_jump_target=False), 692 Instruction(opname='LOAD_FAST', opcode=124, arg=2, argval='inner', argrepr='in ner', offset=34, starts_line=6, is_jump_target=False),
694 Instruction(opname='LOAD_FAST', opcode=124, arg=2, argval='inner', argrepr='in ner', offset=36, starts_line=6, is_jump_target=False), 693 Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr=' ', offset=36, starts_line=None, is_jump_target=False),
695 Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr=' ', offset=38, starts_line=None, is_jump_target=False),
696 ] 694 ]
697 695
698 expected_opinfo_inner = [ 696 expected_opinfo_inner = [
699 Instruction(opname='LOAD_GLOBAL', opcode=116, arg=0, argval='print', argrepr=' print', offset=0, starts_line=4, is_jump_target=False), 697 Instruction(opname='LOAD_GLOBAL', opcode=116, arg=0, argval='print', argrepr=' print', offset=0, starts_line=4, is_jump_target=False),
700 Instruction(opname='LOAD_DEREF', opcode=136, arg=0, argval='a', argrepr='a', o ffset=2, starts_line=None, is_jump_target=False), 698 Instruction(opname='LOAD_DEREF', opcode=136, arg=0, argval='a', argrepr='a', o ffset=2, starts_line=None, is_jump_target=False),
701 Instruction(opname='LOAD_DEREF', opcode=136, arg=1, argval='b', argrepr='b', o ffset=4, starts_line=None, is_jump_target=False), 699 Instruction(opname='LOAD_DEREF', opcode=136, arg=1, argval='b', argrepr='b', o ffset=4, starts_line=None, is_jump_target=False),
702 Instruction(opname='LOAD_DEREF', opcode=136, arg=2, argval='c', argrepr='c', o ffset=6, starts_line=None, is_jump_target=False), 700 Instruction(opname='LOAD_DEREF', opcode=136, arg=2, argval='c', argrepr='c', o ffset=6, starts_line=None, is_jump_target=False),
703 Instruction(opname='LOAD_DEREF', opcode=136, arg=3, argval='d', argrepr='d', o ffset=8, starts_line=None, is_jump_target=False), 701 Instruction(opname='LOAD_DEREF', opcode=136, arg=3, argval='d', argrepr='d', o ffset=8, starts_line=None, is_jump_target=False),
704 Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='e', argrepr='e', of fset=10, starts_line=None, is_jump_target=False), 702 Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='e', argrepr='e', of fset=10, starts_line=None, is_jump_target=False),
705 Instruction(opname='LOAD_FAST', opcode=124, arg=1, argval='f', argrepr='f', of fset=12, starts_line=None, is_jump_target=False), 703 Instruction(opname='LOAD_FAST', opcode=124, arg=1, argval='f', argrepr='f', of fset=12, starts_line=None, is_jump_target=False),
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 894
897 self.assertEqual(b.current_offset, tb.tb_lasti) 895 self.assertEqual(b.current_offset, tb.tb_lasti)
898 896
899 def test_from_traceback_dis(self): 897 def test_from_traceback_dis(self):
900 tb = get_tb() 898 tb = get_tb()
901 b = dis.Bytecode.from_traceback(tb) 899 b = dis.Bytecode.from_traceback(tb)
902 self.assertEqual(b.dis(), dis_traceback) 900 self.assertEqual(b.dis(), dis_traceback)
903 901
904 if __name__ == "__main__": 902 if __name__ == "__main__":
905 unittest.main() 903 unittest.main()
OLDNEW
« Doc/library/dis.rst ('K') | « Lib/opcode.py ('k') | Lib/test/test_grammar.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+