{"action":"created","issue":{"url":"https://api.github.com/repos/cython/cython/issues/2529","repository_url":"https://api.github.com/repos/cython/cython","labels_url":"https://api.github.com/repos/cython/cython/issues/2529/labels{/name}","comments_url":"https://api.github.com/repos/cython/cython/issues/2529/comments","events_url":"https://api.github.com/repos/cython/cython/issues/2529/events","html_url":"https://github.com/cython/cython/issues/2529","id":347245131,"node_id":"MDU6SXNzdWUzNDcyNDUxMzE=","number":2529,"title":"(@cython.cfunc + Type Annotation) Fragility","user":{"login":"jbrockmendel","id":8078968,"node_id":"MDQ6VXNlcjgwNzg5Njg=","avatar_url":"https://avatars1.githubusercontent.com/u/8078968?v=4","gravatar_id":"","url":"https://api.github.com/users/jbrockmendel","html_url":"https://github.com/jbrockmendel","followers_url":"https://api.github.com/users/jbrockmendel/followers","following_url":"https://api.github.com/users/jbrockmendel/following{/other_user}","gists_url":"https://api.github.com/users/jbrockmendel/gists{/gist_id}","starred_url":"https://api.github.com/users/jbrockmendel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jbrockmendel/subscriptions","organizations_url":"https://api.github.com/users/jbrockmendel/orgs","repos_url":"https://api.github.com/users/jbrockmendel/repos","events_url":"https://api.github.com/users/jbrockmendel/events{/privacy}","received_events_url":"https://api.github.com/users/jbrockmendel/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-08-03T03:19:18Z","updated_at":"2018-08-03T05:00:31Z","closed_at":null,"author_association":"NONE","body":"Going through some of pandas' cython modules to try to make code valid-python where possible, I'm seeing cythonize-time errors.  It seems like some combinations are invalid for surprising reasons, e.g:\r\n\r\n```\r\ncpdef object get_rule_month(object source, object default='DEC')\r\n# existing, works as expected\r\n\r\ncpdef object get_rule_month(source: object, default: object='DEC'):\r\n# seems OK\r\n\r\ncpdef get_rule_month(source: object, default: object='DEC') -> object:\r\n# breaks --> Syntax error in C variable declaration\r\n\r\n@cython.ccall\r\ndef get_rule_month(source: object, default: object='DEC') -> object:\r\n# breaks --> Exception clause not allowed for function returning Python object\r\n\r\n@cython.ccall\r\ndef object get_rule_month(source: object, default: object='DEC'):\r\n# breaks --> Expected '(', found 'get_rule_month'\r\n\r\n@cython.ccall\r\n@cython.returns(object)\r\ndef get_rule_month(source: object, default: object='DEC'):\r\n# appears OK\r\n```\r\n\r\nAnother example with a slightly different set of errors:\r\n\r\n```\r\ncdef inline bint is_null_datetime64(v):\r\n# existing, OK\r\n\r\ncdef inline is_null_datetime64(v) -> bint:\r\n# breaks --> Syntax error in C variable declaration\r\n\r\n@cython.cfunc\r\ndef inline is_null_datetime64(v) -> bint:\r\n# breaks --> Expected '(', found 'is_null_datetime64\r\n\r\n@cython.cfunc\r\n@cython.inline\r\ndef is_null_datetime64(v) -> bint:\r\n# breaks --> Function signature does not match previous declaration\r\n```\r\n\r\nThis last one here is the one that is noticeably different from the first example.\r\n\r\nIs this behavior intentional?"},"comment":{"url":"https://api.github.com/repos/cython/cython/issues/comments/410144973","html_url":"https://github.com/cython/cython/issues/2529#issuecomment-410144973","issue_url":"https://api.github.com/repos/cython/cython/issues/2529","id":410144973,"node_id":"MDEyOklzc3VlQ29tbWVudDQxMDE0NDk3Mw==","user":{"login":"scoder","id":491659,"node_id":"MDQ6VXNlcjQ5MTY1OQ==","avatar_url":"https://avatars0.githubusercontent.com/u/491659?v=4","gravatar_id":"","url":"https://api.github.com/users/scoder","html_url":"https://github.com/scoder","followers_url":"https://api.github.com/users/scoder/followers","following_url":"https://api.github.com/users/scoder/following{/other_user}","gists_url":"https://api.github.com/users/scoder/gists{/gist_id}","starred_url":"https://api.github.com/users/scoder/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scoder/subscriptions","organizations_url":"https://api.github.com/users/scoder/orgs","repos_url":"https://api.github.com/users/scoder/repos","events_url":"https://api.github.com/users/scoder/events{/privacy}","received_events_url":"https://api.github.com/users/scoder/received_events","type":"User","site_admin":false},"created_at":"2018-08-03T05:00:31Z","updated_at":"2018-08-03T05:00:31Z","author_association":"CONTRIBUTOR","body":"Thanks for that list (and for trying it in the first place). It means we clearly lack tests here, and it's good to have real-world feedback about where people encounter real-world problems.\r\n\r\nRegarding the \"obvious\" cases:\r\n\r\n> `def inline func()`\r\n\r\nThis can never work, because `def` requires Python syntax. Similarly, `cdef`/`cpdef` syntax cannot be combined with `->` return type annotations, which are a Python `def` function feature. While `cpdef` + Python syntax is a debatable edge case, I'd suggest that providing the return type like this should stay illegal for now. Either you use Python syntax (`def ... -> type`) or Cython syntax (`cpdef type ...`), not both. There are probably ways to give better error messages here (I created #2530 for that).\r\n\r\nThere is an `@cython.inline` decorator, so the (currently) only correct way to use `inline` in Python code is\r\n```cython\r\n@cython.cfunc\r\n@cython.inline\r\ndef is_null_datetime64(v) -> bint:\r\n```\r\nThere is a (similar) test for this in our test suite, so I don't know right now why this would fail. Probably something trivial.\r\n\r\nhttps://github.com/cython/cython/blob/0fb73f66696e52f6614305d0ad6d42521fd128b0/tests/run/pure_py3.py#L68-L70\r\n\r\nSimilarly, `cpdef` should be expressed like this:\r\n```cython\r\n@cython.ccall\r\ndef get_rule_month(source: object, default: object='DEC') -> object:\r\n```\r\nwhich also fails for you, as you said. I remember noticing this kind of error, too, and fixing something in that corner recently. Could you try the latest master on that?"}}
{"actor":{"display_login":"scoder"}}