Clarification on Pure Python mode

25 views
Skip to first unread message

Blue

unread,
Aug 1, 2021, 1:53:51 AM8/1/21
to cython-users
In the Pyrex syntax I can declare an attribute as following:

    cdef str username

But Cython does not expose a `cython.str` (only `cython.basestring` and `cython.unicode` as found in Shadow.py). So would the above become `cython.unicode` (see the following)?

    username: cython.unicode

Another question, how are typehints handled when Pure Python mode is used? Obviously not all typehints can be used to Cython's knowledge, so how does Cython pick which ones to utilize? Are only typehints under the `cython` namespace utilized?

Any place in the source I can be redirected to read about this? I've been meaning to get to know the project better :)

Stefan Behnel

unread,
Aug 1, 2021, 2:02:30 AM8/1/21
to cython...@googlegroups.com
Hi,

Am 1. August 2021 00:56:22 MESZ schrieb Blue:
>In the Pyrex syntax I can declare an attribute as following:
>
> cdef str username
>
>But Cython does not expose a `cython.str` (only `cython.basestring` and
>`cython.unicode` as found in Shadow.py). So would the above become
>`cython.unicode` (see the following)?
>
> username: cython.unicode

If you want str, use str. The two cython.* types are only provided because Py3 does not have them.


>Another question, how are typehints handled when Pure Python mode is used?
>Obviously not all typehints can be used to Cython's knowledge, so how does
>Cython pick which ones to utilize? Are only typehints under the `cython`
>namespace utilized?

No, anything out understands will be used. Die everything else, you get a warning.


>Any place in the source I can be redirected to read about this? I've been
>meaning to get to know the project better :)

Don't have my laptop right now, but look out for annotation_as_type and analyse_as_type.

Stefan

Blue

unread,
Aug 3, 2021, 3:57:02 AM8/3/21
to cython-users
I assume you meant "For everything else", thank you for the clarification. Always a pleasure talking to you Stefan!
Reply all
Reply to author
Forward
0 new messages