Js2Py icon indicating copy to clipboard operation
Js2Py copied to clipboard

KeyError in python3.12.0

Open LeadroyaL opened this issue 2 years ago β€’ 5 comments

# python --version
Python 3.12.0

# pipdeptree
Js2Py==0.74
β”œβ”€β”€ pyjsparser [required: >=2.5.1, installed: 2.7.1]
β”œβ”€β”€ six [required: >=1.10, installed: 1.16.0]
└── tzlocal [required: >=1.2, installed: 5.1]
    └── tzdata [required: Any, installed: 2023.3]

# cat .\test.py
import js2py
Traceback (most recent call last):
  File "D:\PycharmProjects\test.py", line 1, in <module>
    import js2py
  File "D:\Python\Python312\Lib\site-packages\js2py\__init__.py", line 72, in <module>
    from .base import PyJsException
  File "D:\Python\Python312\Lib\site-packages\js2py\base.py", line 2965, in <module>
    @Js
     ^^
  File "D:\Python\Python312\Lib\site-packages\js2py\base.py", line 165, in Js
    return PyJsFunction(val, FunctionPrototype)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Python\Python312\Lib\site-packages\js2py\base.py", line 1377, in __init__
    cand = fix_js_args(func)
           ^^^^^^^^^^^^^^^^^
  File "D:\Python\Python312\Lib\site-packages\js2py\utils\injector.py", line 27, in fix_js_args
    code = append_arguments(six.get_function_code(func), ('this', 'arguments'))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Python\Python312\Lib\site-packages\js2py\utils\injector.py", line 121, in append_arguments
    arg = name_translations[inst.arg]
          ~~~~~~~~~~~~~~~~~^^^^^^^^^^
KeyError: 3

Process finished with exit code 1

LeadroyaL avatar Oct 13 '23 23:10 LeadroyaL

Assuming this was a very simple test since no code was shared. Might have to do with changes made in 3.12, idk, 3.11 initially broke support too. I'll force an update through AUR and see if I can reproduce over the weekend.

worstperson avatar Oct 14 '23 02:10 worstperson

Assuming this was a very simple test since no code was shared. Might have to do with changes made in 3.12, idk, 3.11 initially broke support too. I'll force an update through AUR and see if I can reproduce over the weekend.

code is there

python3.12 -c "import js2py"

miigotu avatar Oct 24 '23 06:10 miigotu

Sorry, I didn't have a solution so I avoided replying. It's crashing because of a change in the bytecode described here https://docs.python.org/3/library/dis.html#opcode-LOAD_ATTR corresponding to this line of the disassembly 14 LOAD_ATTR 3 (NULL|self + is_undefined) In previous versions it was 16 LOAD_METHOD 1 (is_undefined)

It looks like the code that generates the 'names' table needs to be updated to include these new expressions, but I don't fully understand the code, so more testing and research needs to be done before I can suggest a patch and I haven't really found the time for it.

worstperson avatar Oct 24 '23 23:10 worstperson

Have any solution for this issue.

RiteshEdugorilla avatar Jan 24 '24 07:01 RiteshEdugorilla

Please try https://github.com/PiotrDabkowski/Js2Py/pull/327 which at least passes simple_test for me :)

felixonmars avatar Apr 17 '24 13:04 felixonmars