metapensiero.pj icon indicating copy to clipboard operation
metapensiero.pj copied to clipboard

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

Open exander77 opened this issue 4 years ago • 5 comments

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.

exander77 avatar Jan 18 '21 23:01 exander77

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.

lucianolev avatar Jan 20 '21 00:01 lucianolev

@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.

azazel75 avatar Jan 20 '21 00:01 azazel75

@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?

lucianolev avatar Jan 21 '21 13:01 lucianolev

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:

  • the immediate parent of the function is a class ast node;
  • the first of the arguments is named self.

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:

azazel75 avatar Jan 23 '21 12:01 azazel75

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.

zaun avatar Apr 08 '24 05:04 zaun