Adjusted the dis viewer and the relevant debug client part to the changes of Python 3.13. eric7

Tue, 15 Oct 2024 16:29:36 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 15 Oct 2024 16:29:36 +0200
branch
eric7
changeset 10979
960fe726594c
parent 10978
0373041ce25a
child 10980
40e1979abdb7
child 10983
8b9913066b8c

Adjusted the dis viewer and the relevant debug client part to the changes of Python 3.13.

src/eric7/DebugClients/Python/DebugBase.py file | annotate | diff | comparison | revisions
src/eric7/UI/PythonDisViewer.py file | annotate | diff | comparison | revisions
--- a/src/eric7/DebugClients/Python/DebugBase.py	Tue Oct 15 12:07:51 2024 +0200
+++ b/src/eric7/DebugClients/Python/DebugBase.py	Tue Oct 15 16:29:36 2024 +0200
@@ -1065,14 +1065,30 @@
 
         # 1. disassembly info
         for instr in dis.get_instructions(co):
-            instrDict = {
-                "lineno": 0 if instr.starts_line is None else instr.starts_line,
-                "isJumpTarget": instr.is_jump_target,
-                "offset": instr.offset,
-                "opname": instr.opname,
-                "arg": instr.arg,
-                "argrepr": instr.argrepr,
-            }
+            instrDict = (
+                {
+                    "lineno": 0 if instr.starts_line is None else instr.starts_line,
+                    "starts_line": instr.starts_line is not None,
+                    "isJumpTarget": instr.is_jump_target,
+                    "offset": instr.offset,
+                    "opname": instr.opname,
+                    "arg": instr.arg,
+                    "argrepr": instr.argrepr,
+                    "label": "dummy_label" if instr.is_jump_target else "",
+                    # IDE might be 3.13.0+
+                }
+                if sys.version_info < (3, 13, 0)
+                else {
+                    "lineno": 0 if instr.line_number is None else instr.line_number,
+                    "starts_line": instr.starts_line,
+                    "isJumpTarget": instr.is_jump_target,
+                    "offset": instr.offset,
+                    "opname": instr.opname,
+                    "arg": instr.arg,
+                    "argrepr": instr.argrepr,
+                    "label": "" if instr.label is None else instr.label,
+                }
+            )
             disDict["instructions"].append(instrDict)
 
         # 2. code info
--- a/src/eric7/UI/PythonDisViewer.py	Tue Oct 15 12:07:51 2024 +0200
+++ b/src/eric7/UI/PythonDisViewer.py	Tue Oct 15 16:29:36 2024 +0200
@@ -11,6 +11,7 @@
 import dis
 import enum
 import os
+import sys
 
 from PyQt6.QtCore import Qt, QTimer, pyqtSlot
 from PyQt6.QtGui import QBrush
@@ -337,7 +338,13 @@
         fields = []
         # Column: Source code line number (right aligned)
         if instr.starts_line:
-            fields.append("{0:d}".format(instr.starts_line))
+            fields.append(
+                "{0:d}".format(
+                    instr.starts_line
+                    if sys.version_info < (3, 13)
+                    else instr.line_number
+                )
+            )
         else:
             fields.append("")
         # Column: Instruction offset from start of code sequence
@@ -514,15 +521,30 @@
             lasti = disassembly["lasti"]
             lastStartItem = None
             for instrDict in disassembly["instructions"]:
-                instr = dis.Instruction(
-                    instrDict["opname"],
-                    0,  # dummy value
-                    instrDict["arg"],
-                    "",  # dummy value
-                    instrDict["argrepr"],
-                    instrDict["offset"],
-                    instrDict["lineno"],
-                    instrDict["isJumpTarget"],
+                instr = (
+                    dis.Instruction(
+                        instrDict["opname"],
+                        0,  # dummy value
+                        instrDict["arg"],
+                        "",  # dummy value
+                        instrDict["argrepr"],
+                        instrDict["offset"],
+                        instrDict["lineno"],
+                        instrDict["isJumpTarget"],
+                    )
+                    if sys.version_info < (3, 13, 0)
+                    else dis.Instruction(
+                        instrDict["opname"],
+                        0,  # dummy value
+                        instrDict["arg"],
+                        "",  # dummy value
+                        instrDict["argrepr"],
+                        instrDict["offset"],
+                        instrDict["offset"],
+                        instrDict["starts_line"],
+                        instrDict["lineno"],
+                        instrDict["label"] if instrDict["label"] else None,
+                    )
                 )
                 if instrDict["lineno"] > 0:
                     if lastStartItem:

eric ide

mercurial