cython/cython

Coercing a sliced C array to Python should create a list

Open

#2,159 opened on Mar 17, 2018

View on GitHub
 (3 comments) (0 reactions) (0 assignees)Python (8,663 stars) (1,517 forks)batch import
Cython Language FeatureType Analysisenhancementgood first issuehelp wanted

Description

Cython already copies a C array into a Python list automatically on object coercion. It should do the same for sliced C arrays, e.g.

def test():
    cdef int i
    cdef int a[100]
    for i in range(100):
        a[i] = i**2
    return a[:20]  # rejected by type analysis

Currently results in Cannot convert 'int *' to Python object.

Contributor guide