Skip to content

Commit

Permalink
[py] Avoid Python keywords for identifiers starting with an uppercase…
Browse files Browse the repository at this point in the history
… letter.
  • Loading branch information
pfusik committed Nov 7, 2023
1 parent f021ed0 commit 01c35e1
Show file tree
Hide file tree
Showing 5 changed files with 444 additions and 6 deletions.
45 changes: 44 additions & 1 deletion GenPy.fu
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,48 @@ public class GenPy : GenPySwift
case "this":
Write("self");
break;
case "And":
case "Array":
case "As":
case "Assert":
case "Async":
case "Await":
case "Break":
case "Class":
case "Continue":
case "Def":
case "Del":
case "Dict":
case "Elif":
case "Else":
case "Enum":
case "Except":
case "Finally":
case "For":
case "From":
case "Global":
case "If":
case "Import":
case "In":
case "Is":
case "Lambda":
case "Len":
case "List":
case "Math":
case "Nonlocal":
case "Not":
case "Or":
case "Pass":
case "Pyfma":
case "Raise":
case "Re":
case "Return":
case "Str":
case "Sys":
case "Try":
case "While":
case "With":
case "Yield":
case "and":
case "array":
case "as":
Expand Down Expand Up @@ -128,11 +170,12 @@ public class GenPy : GenPySwift
case "pyfma":
case "raise":
case "re":
case "str":
case "sys":
case "try":
case "with":
case "yield":
Write(name);
WriteCamelCase(name);
WriteChar('_');
break;
default:
Expand Down
4 changes: 2 additions & 2 deletions libfut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21873,8 +21873,8 @@ void GenPy::writeNameNotKeyword(std::string_view name)
{
if (name == "this")
write("self");
else if (name == "and" || name == "array" || name == "as" || name == "async" || name == "await" || name == "def" || name == "del" || name == "dict" || name == "elif" || name == "enum" || name == "except" || name == "finally" || name == "from" || name == "global" || name == "import" || name == "is" || name == "lambda" || name == "len" || name == "list" || name == "math" || name == "nonlocal" || name == "not" || name == "or" || name == "pass" || name == "pyfma" || name == "raise" || name == "re" || name == "sys" || name == "try" || name == "with" || name == "yield") {
write(name);
else if (name == "And" || name == "Array" || name == "As" || name == "Assert" || name == "Async" || name == "Await" || name == "Break" || name == "Class" || name == "Continue" || name == "Def" || name == "Del" || name == "Dict" || name == "Elif" || name == "Else" || name == "Enum" || name == "Except" || name == "Finally" || name == "For" || name == "From" || name == "Global" || name == "If" || name == "Import" || name == "In" || name == "Is" || name == "Lambda" || name == "Len" || name == "List" || name == "Math" || name == "Nonlocal" || name == "Not" || name == "Or" || name == "Pass" || name == "Pyfma" || name == "Raise" || name == "Re" || name == "Return" || name == "Str" || name == "Sys" || name == "Try" || name == "While" || name == "With" || name == "Yield" || name == "and" || name == "array" || name == "as" || name == "async" || name == "await" || name == "def" || name == "del" || name == "dict" || name == "elif" || name == "enum" || name == "except" || name == "finally" || name == "from" || name == "global" || name == "import" || name == "is" || name == "lambda" || name == "len" || name == "list" || name == "math" || name == "nonlocal" || name == "not" || name == "or" || name == "pass" || name == "pyfma" || name == "raise" || name == "re" || name == "str" || name == "sys" || name == "try" || name == "with" || name == "yield") {
writeCamelCase(name);
writeChar('_');
}
else
Expand Down
45 changes: 44 additions & 1 deletion libfut.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22662,6 +22662,48 @@ void WriteNameNotKeyword(string name)
case "this":
Write("self");
break;
case "And":
case "Array":
case "As":
case "Assert":
case "Async":
case "Await":
case "Break":
case "Class":
case "Continue":
case "Def":
case "Del":
case "Dict":
case "Elif":
case "Else":
case "Enum":
case "Except":
case "Finally":
case "For":
case "From":
case "Global":
case "If":
case "Import":
case "In":
case "Is":
case "Lambda":
case "Len":
case "List":
case "Math":
case "Nonlocal":
case "Not":
case "Or":
case "Pass":
case "Pyfma":
case "Raise":
case "Re":
case "Return":
case "Str":
case "Sys":
case "Try":
case "While":
case "With":
case "Yield":
case "and":
case "array":
case "as":
Expand Down Expand Up @@ -22689,11 +22731,12 @@ void WriteNameNotKeyword(string name)
case "pyfma":
case "raise":
case "re":
case "str":
case "sys":
case "try":
case "with":
case "yield":
Write(name);
WriteCamelCase(name);
WriteChar('_');
break;
default:
Expand Down
45 changes: 44 additions & 1 deletion libfut.js
Original file line number Diff line number Diff line change
Expand Up @@ -23237,6 +23237,48 @@ export class GenPy extends GenPySwift
case "this":
this.write("self");
break;
case "And":
case "Array":
case "As":
case "Assert":
case "Async":
case "Await":
case "Break":
case "Class":
case "Continue":
case "Def":
case "Del":
case "Dict":
case "Elif":
case "Else":
case "Enum":
case "Except":
case "Finally":
case "For":
case "From":
case "Global":
case "If":
case "Import":
case "In":
case "Is":
case "Lambda":
case "Len":
case "List":
case "Math":
case "Nonlocal":
case "Not":
case "Or":
case "Pass":
case "Pyfma":
case "Raise":
case "Re":
case "Return":
case "Str":
case "Sys":
case "Try":
case "While":
case "With":
case "Yield":
case "and":
case "array":
case "as":
Expand Down Expand Up @@ -23264,11 +23306,12 @@ export class GenPy extends GenPySwift
case "pyfma":
case "raise":
case "re":
case "str":
case "sys":
case "try":
case "with":
case "yield":
this.write(name);
this.writeCamelCase(name);
this.writeChar(95);
break;
default:
Expand Down
Loading

0 comments on commit 01c35e1

Please sign in to comment.