New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pure-Python compatible "not None", "const" #2695

Open
jbrockmendel opened this Issue Nov 1, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@jbrockmendel

jbrockmendel commented Nov 1, 2018

Three goals are currently coming into conflict:

  • wanting to move code from ndarray[foo_t] to foo_t[:]
  • needing to reject None and allow read-only arrays
  • wanting to move towards valid-python

The first two I can accomplish with const foo_t[:] not None, but that blows the third out of the water. Any thoughts on syntax (decorators?) to accomplish this in pure python mode?

@scoder

This comment has been minimized.

Contributor

scoder commented Nov 1, 2018

Regarding not None, this can be done with an explicit None check in both Python and Cython. I don't think we should create any special semantics here. (But I created #2696 anyway, just to keep it in mind.)

It's true that const is not currently available as a pure Python type modifier. Not sure how difficult that is, given that it's a plain modifier in C, but would have to be a function in Python, like

def func(data: cython.const(cython.int)[:]): ...

Requiring a typedef() here seems a bit overkill.
Worth trying out, in any case. PR welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment