metapensiero / metapensiero.pj

Javascript for refined palates: a Python 3 to ES6 Javascript translator
Other
901 stars 73 forks source link

UnsupportedSyntaxError: Node type 'FunctionDef': Line: 3, column: 4. First arg on method must be 'self' #56

Open exander77 opened 3 years ago

exander77 commented 3 years ago

Self-reference does not need to be named self but can have any name, that's why We write it there. If it was always self there would be no point to write it there.

lucianolev commented 3 years ago

I should add that for class methods, standard practice is for the first parameter to be named "cls", so this also fails for common class methods.

azazel75 commented 3 years ago

@lucianolev thanks, that's a more useful reason to fix this up, as soon as I have some time to spare on this even if at the moment I'm not using it.

lucianolev commented 3 years ago

@azazel75 Thanks! If you guide me, maybe I can try to fix it. Do you think it's a deep change or something relatively easy to change?

azazel75 commented 3 years ago

No, it's not deep: the check is here https://github.com/metapensiero/metapensiero.pj/blob/6c6cd34a38989bbd10050c33e401111fdc4d8d18/src/metapensiero/pj/transformations/classes.py#L162 which is where classess gets translated and then it's used into the function translator here https://github.com/metapensiero/metapensiero.pj/blob/6c6cd34a38989bbd10050c33e401111fdc4d8d18/src/metapensiero/pj/transformations/functions.py#L81 . The function translator is the same as the method translator and differentiates the two using two methods:

now, the latter may seem silly, but it may be a simple way to "do the right thing" in some corner cases. Unfortunately I don't remember what those are and if the testing checks them. But really may be sufficient just to "relax" the check to not raise the error :stuck_out_tongue_winking_eye:

zaun commented 6 months ago

Its been a few years sense an update to the repo so I'm no sure if this is still active or not. But I am still seeing this issue when I try to convert a python script.