self should be VariableName, not keyword #6

Closed
R167 wants to merge 1 commit from self-not-keyword into master
R167 commented 2021-02-17 01:08:14 +01:00 (Migrated from github.com)

In Python, the variable name self is used only by convention and does not actually carry any special meaning. As such, it should be treated as a variable name.

The following program is legal, but would require any program using leze-python to handle VariableName | self type.

self = True

Current: Script(AssignStatement(self,AssignOp,Boolean))
Expected: Script(AssignStatement(VariableName,AssignOp,Boolean))

Example of how this currently has to be handled (for all params, lambdas, etc.)

switch (cursor.node.type.name) {
  case "VariableName":
  case "self":
    // handle variable
  ...
}

On the topic of self in python, here's an oldy-but-goody on python's use of explicit self (and by extension why it's not a reserved word).

In Python, the variable name `self` is used only by convention and does not actually carry any special meaning. As such, it should be treated as a variable name. The following program is legal, but would require any program using leze-python to handle `VariableName | self` type. ```python self = True ``` Current: `Script(AssignStatement(self,AssignOp,Boolean))` Expected: `Script(AssignStatement(VariableName,AssignOp,Boolean))` Example of how this currently has to be handled (for all params, lambdas, etc.) ```typescript switch (cursor.node.type.name) { case "VariableName": case "self": // handle variable ... } ``` On the topic of self in python, here's an oldy-but-goody on python's use of [explicit self](http://neopythonic.blogspot.com/2008/10/why-explicit-self-has-to-stay.html) (and by extension why it's not a reserved word).
marijnh commented 2021-02-17 09:04:14 +01:00 (Migrated from github.com)

Great to have someone who's more familiar with the language look over the grammar. Merged!

Great to have someone who's more familiar with the language look over the grammar. Merged!
R167 commented 2021-02-18 07:12:53 +01:00 (Migrated from github.com)

Awesome, marking as closed (since GitHub didn't auto detect?)

Awesome, marking as closed (since GitHub didn't auto detect?)
marijnh commented 2021-02-18 14:50:37 +01:00 (Migrated from github.com)

Ah, indeed, I rebased over your other PR so it didn't recognize the commit hash.

Ah, indeed, I rebased over your other PR so it didn't recognize the commit hash.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lezer/python!6
No description provided.