MatthieuDartiailh / bytecode

Python module to modify bytecode
https://bytecode.readthedocs.io/
MIT License
302 stars 38 forks source link

except Exception as e fails on Python 3.11 #118

Closed bburan closed 1 year ago

bburan commented 1 year ago
import textwrap
from bytecode import Bytecode, ControlFlowGraph

source = '''
try:
    pass
except Exception as e:
    pass
'''
source = textwrap.dedent(source).strip()
code = compile(source, '<string>', 'exec')
bytecode = Bytecode.from_code(code)
cfg = ControlFlowGraph.from_bytecode(bytecode)
cfg.to_bytecode()

Gives the following traceback:

Traceback (most recent call last):
  File "c:\Users\lbhb\projects\psi-nafc\src\test_bytecode.py", line 15, in <module>
    cfg.to_bytecode()
  File "c:\Users\lbhb\anaconda3\envs\psi-nafc\Lib\site-packages\bytecode\cfg.py", line 992, in to_bytecode
    byt_te.entry.stack_depth = min(
                               ^^^^
TypeError: '<' not supported between instances of '_UNSET' and '_UNSET'
MatthieuDartiailh commented 1 year ago

Thanks for the report !