Aaron DeVore wrote:
> I have an application that could benefit from using sets. Currently
> I'm using lists but I'd like to avoid linear time when I can get
> constant time. The set type is the best option for me but my
> application has to also work with Python versions 2.3-2.5. I have seen
> people use this trick for backward compatibility (---- is used for
> indentation):
>
> cdef object set
> try:
> ----set = __builtins__.set
> except AttributeError:
> ----from sets import Set as set
>
> When using this trick will Cython still use PySet_* in the Python API
> where available?

It can't use PySet_* anyway, as they are not available in Py2.3, and
Cython code currently runs with 2.3. Although I wouldn't mind restricting
the C code to Py2.4 if "set" is not redefined in the source (maybe that's
already the case, haven't checked).


> As a side note, how about making an adjustment to Cython that
> automatically handles the set type/sets module trick?

Yes, it would be nice to have that. The idea would be to do the Set import
internally, to provide replacement implementations for the generated
PySet_*() calls that work at the Python level, and to enable that
machinery when the C compile-time Python version is Py2.3. However, that's
work that someone has to do.

OTOH, this is a pure legacy feature for code that must run with Py2.3. I
guess people (including myself) can currently live with the little
performance impact regarding the set operations (which are fast anyway),
given the gain that their code runs unchanged in Py2.3.

Stefan

_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to