tuple unpacking in argument list.

92 views
Skip to first unread message

Chris Barker

unread,
Nov 8, 2012, 7:51:40 PM11/8/12
to cython-users
Folks,

I am setting out to Cythonize a function, and found that Cython does
not appear to support tuple unpacking in function arguments. This is
perfectly legal Python:

def test_tuple_unpack((x_1, y_1), (x_2, y_2)):
print x_1, y_1, x_2, y_2

but when I try to run Cython on it:

$ cython tuple_unpack_args.pyx

Error compiling Cython file:
------------------------------------------------------------
...
def test_nested_tuples((x_1, y_1), (x_2, y_2)):
^
------------------------------------------------------------

tuple_unpack_args.pyx:1:27: Expected ')', found ','

$ cython --version
Cython version 0.17.1

Whether we want to support this I don't know, but if the goal is to be
able to compile all legal python, then this is a missing feature.

-Chris



--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris....@noaa.gov

Stefan Behnel

unread,
Nov 9, 2012, 1:57:03 AM11/9/12
to cython...@googlegroups.com
Chris Barker, 09.11.2012 01:51:
> I am setting out to Cythonize a function, and found that Cython does
> not appear to support tuple unpacking in function arguments. This is
> perfectly legal Python:

Python 2, to be exact.


> def test_tuple_unpack((x_1, y_1), (x_2, y_2)):
> print x_1, y_1, x_2, y_2
>
> but when I try to run Cython on it:
>
> $ cython tuple_unpack_args.pyx
>
> Error compiling Cython file:
> ------------------------------------------------------------
> ...
> def test_nested_tuples((x_1, y_1), (x_2, y_2)):
> ^
> ------------------------------------------------------------
>
> tuple_unpack_args.pyx:1:27: Expected ')', found ','
>
> $ cython --version
> Cython version 0.17.1
>
> Whether we want to support this I don't know, but if the goal is to be
> able to compile all legal python, then this is a missing feature.

Well, it's a known limitation at least.

http://trac.cython.org/cython_trac/ticket/692

Given that it's a dead feature that requires a dedicated, non-trivial
implementation (unnamed function arguments) but that is very easy to work
around, there hasn't been any move to support it yet.

Stefan

Chris Barker

unread,
Nov 9, 2012, 2:33:49 PM11/9/12
to cython...@googlegroups.com
On Thu, Nov 8, 2012 at 10:57 PM, Stefan Behnel <stef...@behnel.de> wrote:

>> not appear to support tuple unpacking in function arguments. This is
>> perfectly legal Python:
>
> Python 2, to be exact.

I see -- I've paid far too little attention to Python 3 -- I didn't
realize this was depreciated.

> Well, it's a known limitation at least.
>
> http://trac.cython.org/cython_trac/ticket/692

I should have searched the tickets, clearly!

But maybe it should be mentioned here:

http://docs.cython.org/src/userguide/limitations.html

(which has nothing in it now!)

or at least the ticket could be assigned to the "Python Semantics"
component, so it will show up here:

http://trac.cython.org/cython_trac/query?status=assigned&status=new&status=reopened&component=Python+Semantics&component=Python3+Semantics&order=priority&col=id&col=summary&col=component&col=status&col=type&col=priority&col=milestone

Should I do that? I _think_ I have TRAC access.

> Given that it's a dead feature that requires a dedicated, non-trivial
> implementation (unnamed function arguments) but that is very easy to work
> around, there hasn't been any move to support it yet.

Fair enough.

-thx.

Stefan Behnel

unread,
Nov 9, 2012, 2:42:00 PM11/9/12
to cython...@googlegroups.com
Chris Barker, 09.11.2012 20:33:
> On Thu, Nov 8, 2012 at 10:57 PM, Stefan Behnel wrote:
>>> not appear to support tuple unpacking in function arguments. This is
>>> perfectly legal Python:
>>
>> Python 2, to be exact.
>
> I see -- I've paid far too little attention to Python 3 -- I didn't
> realize this was depreciated.
>
>> Well, it's a known limitation at least.
>>
>> http://trac.cython.org/cython_trac/ticket/692
>
> I should have searched the tickets, clearly!
>
> But maybe it should be mentioned here:
>
> http://docs.cython.org/src/userguide/limitations.html
>
> (which has nothing in it now!)

AFAIR, there was some content a while ago, but it became outdated and was
removed, likely around 0.15 when the last major Python features went in.
Good call, I've changed the "Component".

Stefan

Reply all
Reply to author
Forward
0 new messages