[GRASS-dev] [GRASS GIS] #3835: v.distance returns a 'Syntax error' when used from python

#3835: v.distance returns a 'Syntax error' when used from python
----------------------+-------------------------
Reporter: epifanio | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone:
Component: Vector | Version: svn-trunk
Keywords: | CPU: x86-64
Platform: Linux |
----------------------+-------------------------
Trying to run `v.distance` from `grass.script.run_command()` returns a
syntax error

{{{
import grass.script as grass
grass.run_command('v.db.addcolumn',
     map='points_of_interest',
     columns="distance double precision")

grass.run_command('v.distance',
                   from='points_of_interest',
                   to='points_of_interest',
                   upload='distance',
                   column='distance')
File "<ipython-input-9-28b7e4b9716c>", line 2
   from='points_of_interest',
        ^
SyntaxError: invalid syntax
}}}

Tested on:

GRASS GIS version: grass-ci on github
{{{
git rev-parse --short HEAD
2860974f
}}}
GRASS LOCATION: nc_basic_spm_grass7

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3835&gt;
GRASS GIS <https://grass.osgeo.org>

#3835: v.distance returns a 'Syntax error' when used from python3
-----------------------+-------------------------
  Reporter: epifanio | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone:
Component: Vector | Version: svn-trunk
Resolution: | Keywords:
       CPU: x86-64 | Platform: Linux
-----------------------+-------------------------

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3835#comment:1&gt;
GRASS GIS <https://grass.osgeo.org>

#3835: v.distance returns a 'Syntax error' when used from python
-----------------------+-------------------------
  Reporter: epifanio | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone:
Component: Vector | Version: svn-trunk
Resolution: | Keywords:
       CPU: x86-64 | Platform: Linux
-----------------------+-------------------------

Comment (by epifanio):

The issue affect both python2 and python3

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3835#comment:2&gt;
GRASS GIS <https://grass.osgeo.org>

#3835: v.distance returns a 'Syntax error' when used from python
-----------------------+-------------------------
  Reporter: epifanio | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone:
Component: Vector | Version: svn-trunk
Resolution: | Keywords:
       CPU: x86-64 | Platform: Linux
-----------------------+-------------------------

Comment (by lucadelu):

Try to use `from_`

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3835#comment:3&gt;
GRASS GIS <https://grass.osgeo.org>

#3835: v.distance returns a 'Syntax error' when used from python
-----------------------+-------------------------
  Reporter: epifanio | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone:
Component: Vector | Version: svn-trunk
Resolution: | Keywords:
       CPU: x86-64 | Platform: Linux
-----------------------+-------------------------

Comment (by pmav99):

{{{from}}} is a Python
"[https://github.com/python/cpython/blob/3.7/Lib/keyword.py#L15-L53
keyword]". This means that the Python parser does not allow them to be
used as identifier names (functions, classes, variables, parameters etc).
If memory serves, when a module argument/option is a Python keyword, then
the python wrapper appends an underscore to its name. I.e. you need to
replace {{{from}}} with {{{from_}}} like @lucadelu suggested.

FYI, there are a few different keywords between python 2 and 3 but for the
most part they are the same. E.g. in Python 2, {{{print}}} used to be a
statement (i.e. a keyword), while in Python 3 it got converted to a
function.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3835#comment:4&gt;
GRASS GIS <https://grass.osgeo.org>

#3835: v.distance returns a 'Syntax error' when used from python
-----------------------+-------------------------
  Reporter: epifanio | Owner: grass-dev@…
      Type: defect | Status: closed
  Priority: normal | Milestone:
Component: Vector | Version: svn-trunk
Resolution: invalid | Keywords:
       CPU: x86-64 | Platform: Linux
-----------------------+-------------------------
Changes (by sbl):

* status: new => closed
* resolution: => invalid

Comment:

OK to close, right?

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3835#comment:5&gt;
GRASS GIS <https://grass.osgeo.org>