Message363663
Code objects themselves supports equality comparisons,
>>> compile("print(1)", "<stdin>", "eval") == compile("print(1)", "<stdin>", "eval")
True
So this patch basically compares the underlying code objects with 2 Bytecode specific attribute, first_line and current_offset. So these objects will be equal
>>> import dis
>>> dis.Bytecode("print(1)") == dis.Bytecode("print(1)")
True
but these won't
>>> dis.Bytecode("print(1)") == dis.Bytecode("print(1)", first_line=2)
False
>>> dis.Bytecode("print(1)") == dis.Bytecode("print(1)", current_offset=12)
False
A simple example that would be problamatic in .dis() method is code objects that contains other code objects
import dis
source = "def x(a, b): print(1)"
print(dis.Bytecode(source).dis())
print(dis.Bytecode(source).dis())
print(dis.Bytecode(source).dis() == dis.Bytecode(source).dis())
1 0 LOAD_CONST 0 (<code object x at !!0x7fd76239aee0!!, file "<disassembly>", line 1>)
2 LOAD_CONST 1 ('x')
4 MAKE_FUNCTION 0
6 STORE_NAME 0 (x)
8 LOAD_CONST 2 (None)
10 RETURN_VALUE
1 0 LOAD_CONST 0 (<code object x at !!0x7fd7623b76c0!!, file "<disassembly>", line 1>)
2 LOAD_CONST 1 ('x')
4 MAKE_FUNCTION 0
6 STORE_NAME 0 (x)
8 LOAD_CONST 2 (None)
10 RETURN_VALUE
False |
|
Date |
User |
Action |
Args |
2020-03-08 14:01:09 | BTaskaya | set | recipients:
+ BTaskaya, steven.daprano |
2020-03-08 14:01:08 | BTaskaya | set | messageid: <1583676068.98.0.142048756184.issue39902@roundup.psfhosted.org> |
2020-03-08 14:01:08 | BTaskaya | link | issue39902 messages |
2020-03-08 14:01:08 | BTaskaya | create | |
|