Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions Doc/whatsnew/3.9.rst
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,12 @@ The :command:`upload` command now creates SHA2-256 and Blake2b-256 hash
digests. It skips MD5 on platforms that block MD5 digest.
(Contributed by Christian Heimes in :issue:`40698`.)

dis
---

:class:`dis.Bytecode` objects now support equality comparisons. (Contributed
by Batuhan Taskaya in :issue:`39902`.)

fcntl
-----

Expand Down
10 changes: 10 additions & 0 deletions Lib/dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,16 @@ def dis(self):
formatter=formatter)
return output.getvalue()

def __eq__(self, other):
if isinstance(other, Bytecode):
return (self.codeobj, self.first_line, self.current_offset) == (
other.codeobj,
other.first_line,
other.current_offset,
)
else:
return NotImplemented


def main(args=None):
import argparse
Expand Down
11 changes: 11 additions & 0 deletions Lib/test/test_dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -2406,6 +2406,17 @@ def test_from_traceback_dis(self):
b = dis.Bytecode.from_traceback(tb)
self.assertEqual(b.dis(), dis_traceback)

def test_equality(self):
self.assertEqual(dis.Bytecode("print(1)"), dis.Bytecode("print(1)"))
self.assertNotEqual(dis.Bytecode("print(1)"), dis.Bytecode("print(2)"))
self.assertNotEqual(
dis.Bytecode("print(1)", first_line=3), dis.Bytecode("print(1)")
)
self.assertNotEqual(
dis.Bytecode("print(1)", current_offset=5),
dis.Bytecode("print(1)"),
)

@requires_debug_ranges()
def test_bytecode_co_positions(self):
bytecode = dis.Bytecode("a=1")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Added support for equality comparisons in ``dis.Bytecode`` objects. Patch by
Batuhan Taskaya.
Loading