Underscore to avoid Python keywords used improperly in grass.script
|Reported by:||wenzeslaus||Owned by:|
|Keywords:||PEP8, python keywords, parser||Cc:|
When a module parameter is the same as one of Python keywords, we are adding and underscore before the name of parameter, so call of a module:
But this is wrong, according to PEP8 and commonly used standard, prefixed underscore means private. To avoid conflicts you should use underscore at the end:
_single_leading_underscore: weak "internal use" indicator. E.g. from M import * does not import objects whose name starts with an underscore. single_trailing_underscore_: used by convention to avoid conflicts with Python keyword, e.g. Tkinter.Toplevel(master, class_='ClassName')
If there are no objections I will commit the change soon hopefully with tests and documentation (in case it is not already documented). Please object now.
I plan to commit in backwards compatible manner, so the old syntax will work (for some time).
The code which will change is in grass.script.core and will look like this:
if opt.startswith('_'): opt = opt[1:] elif opt.endswith('_'): opt = opt[:-1]
if opt.endswith('_'): opt = opt[:-1]
This should go to 7.0 to allow usage of the good way.