TranscryptOrg / Transcrypt

Python 3.9 to JavaScript compiler - Lean, fast, open!
https://www.transcrypt.org
Apache License 2.0
2.82k stars 215 forks source link

Adding two lists converts to a string #848

Closed pvl closed 1 year ago

pvl commented 1 year ago

I'm very new to Transcrypt, but I'm having some trouble understanding why running this code, as a way to append an item to a list, will make the object of type string. Maybe this can be a bug. newlst = list(mylst) + ["X"] console.log(typeof(newlst)) # prints string

On the other hand, if I run the append this way, it will say it is an object and works as expected newlst = list(mylst) newlst.append("X") console.log(typeof(newlst)) # prints object

Used Transcrypt 3.9.1.

JennaSys commented 1 year ago

You may need to enable operator overloads in Transcrypt in order for your first example to work. It is turned off by default because it can result in unnecessary code bloat in the transpiled result. You can either use the # __:opovpragma mechanism to enable it in your code just for the line that needs it, or you can use the --opov compile switch to turn it on globally if having a larger JS module is not an issue.

pvl commented 1 year ago

Thanks, I confirmed it works ok with the pragma.