brython-dev / brython

Brython (Browser Python) is an implementation of Python 3 running in the browser
BSD 3-Clause "New" or "Revised" License
6.39k stars 511 forks source link

isinstance not working with JS arrays #2325

Open denis-migdal opened 11 months ago

denis-migdal commented 11 months ago

isinstance(arr, list)/isinstance(arr, tuple) doesn't work properly on JS arrays (one of them should be true.

Maybe will be fixed by the PR I made a few time back.

PierreQuentel commented 11 months ago

I don't agree that either test should return True, a Javascript Array is not the same type as a Python list or tuple

from browser import window

t = window.js_list
print(hasattr(t, 'push')) # True

t = [1]
print(hasattr(t, 'push')) # False
denis-migdal commented 11 months ago

Shouldn't they convert to one in jsobj2pyobj ?

denis-migdal commented 11 months ago

Or to be put in a wrapper JSList inheriting from List, or JSTuple inheriting from Tuple, depending on what Object.isFrozen(jsarray) returns ?