Open xsfhlzh opened 4 years ago
Unfortunately, as far as I know, the Python language does not provide a mechanism to escape keywords.
We ran into a similar issue when changing None
to a keyword in the IronPython 3 codebase. The recommended workaround is to not use .None
, but getattr
instead. For example, StringSplitOptions.None
is invalid syntax, but StringSplitOptionsNone = getattr(StringSplitOptions, "None")
works.
Thanks slozier! I hope Ironpython makes some changes. Since keywords are not supported as field names, changing them to friendly names is an option. For example: _None = None
I am writing a program which is similar to ironstubs to introduce C# types into ironpython. This helps me write code well in vscode. Some issues have arisen. In Enum, for example, some C# programs often use None as one of them. I use python3.8 as the engine in the python extension of vscode. The extension considers None to be a keyword, so the following code is wrong: class ModeIdentifier (System.Enum): value__ = None #type: int None = None #type: int Move = None #type: int CustomStart = None #type: int I wonder if I can change None to _None in ironpython, or something else so that I won't get an error in the IDE.