On Monday, May 29, 2017 at 2:08:37 AM UTC-6, vdelecroix wrote:
>
> Note that __hex__ is not used anymore in py3 (calling `hex(obj)` goes 
> through `obj.__index__()`). What I proposed in cypari2 [1] is to use 
> Cython macros for py2/py3 changes. That solved all py2/py3 issues we had. 
>
> Ah. So apparently, cython still processes __hex__ as a special method and 
then discovers later there's no slot for it in Py3.
 

> cdef class MyClass(...): 
>      IF PY_MAJOR_VERSION == 2: 
>          def __hex__(self): 
>              ... 
>
>      IF PY_MAJOR_VERSION == 2: 
>          def __oct__(self): 
>              ... 
>
>      IF PY_MAJOR_VERSION == 2: 
>          def __int__(self): 
>              ... 
>
>      IF PY_MAJOR_VERSION == 2: 
>          def __cmp__(self, Gen other): 
>              ... 
>
> That looks like a very good idea.

Note that cythonize allows for a "compile_time_env" argument, which is 
probably a better way to inject the binding for PY_MAJOR_VERSION than by 
writing and importing a "pxi" file. See for instance 
https://git.sagemath.org/sage.git/diff/src/setup.py?id=d34101e8c4a28181a075db0bd8aea34c94154b54
 
for a recent use in sage.
 

>   [1] https://github.com/defeo/cypari2/pull/13 
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to