#2441: Underscore to avoid Python keywords used improperly in grass.script
-------------------------------------------+--------------------------------
Reporter: wenzeslaus | Owner: grass-dev@…
Type: defect | Status: new
Priority: normal | Milestone: 7.0.0
Component: Default | Version: svn-trunk
Keywords: PEP8, python keywords, parser | Platform: Unspecified
Cpu: Unspecified |
-------------------------------------------+--------------------------------
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:
{{{
run_command('s.module', lambda="abc")
}}}
becomes
{{{
run_command('s.module', _lambda="abc")
}}}
But this is wrong, according to
[http://legacy.python.org/dev/peps/pep-0008/ 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]
}}}
or this:
{{{
if opt.endswith('_'):
opt = opt[:-1]
}}}
This should go to 7.0 to allow usage of the good way.
--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2441>
GRASS GIS <http://grass.osgeo.org>