Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
exander77 opened this issue Jan 18, 2021 · 5 comments

Comments

@exander77
Copy link

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
Copy link

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
Copy link
Collaborator

@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
Copy link

@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
Copy link
Collaborator

No, it's not deep: the check is here

t.unsupported(node, len(arg_names) == 0 or arg_names[0] != 'self',
which is where classess gets translated and then it's used into the function translator here
if is_method or (len(arg_names) > 0 and arg_names[0] == 'self'):
. 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 😜

@zaun
Copy link

zaun commented Apr 8, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants