Skip to content

problem with invert operator expression #887

@jggatc

Description

@jggatc

Expression with invert operator of an class instance causes error.

Error occurs with iobj = ~(obj) expression.
Browser error: Uncaught TypeError: Function.prototype.toString called on incompatible object.
Worked properly with iobj = obj.__invert__() expression.

python code:

class Obj:
    def __init__(self, x):
        self.x = x
    def __invert__(self):
        return ~self.x

# __pragma__ ('opov')
def op_invert():
    obj = Obj(42)
    if False:
        iobj = ~(obj)
# __pragma__ ('noopov')

op_invert()

compiled javascript code with ~(obj):

export var op_invert = function () {
	var obj = __call__ (Obj, null, 10);
	var iobj = ~(obj);
};

compiled javascript code with obj.__invert__():

export var op_invert = function () {
	var obj = __call__ (Obj, null, 10);
	var iobj = (function () {
		var __accu0__ = obj;
		return __call__ (__accu0__.__invert__, __accu0__);
	}) ();
};

env: Python3.9 venv with pip install Transcrypt
testing: Firefox version 133 in Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions