Skip to content
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

Spurious "redeclared" warning with fused types and typedef #3111

alex-xnor opened this issue Aug 29, 2019 · 0 comments · May be fixed by #3112


Copy link

commented Aug 29, 2019

The following code:

ctypedef unsigned char npy_uint8
ctypedef unsigned short npy_uint16

ctypedef fused Foo:

ctypedef fused Bar:

def baz(Foo[:] a, Bar[:, :] b):

Seems like it should compile without warnings or errors. However, in practice, it produces a spurious "redeclared" warning:

$ venv/bin/cython -3 example.pyx 
warning: __pyxutil:16:4: '___pyx_npy_uint8' redeclared !!!

From hacking on the code a little to make it spit out the full context for errors, it looks like the declaration it's choking on is from some code that was auto-generated internally as part of the compilation process and was pseudo-named __pyxutil:

cdef extern from *:
    void __pyx_PyErr_Clear "PyErr_Clear" ()
    type __Pyx_ImportNumPyArrayTypeIfAvailable()
    int __Pyx_Is_Little_Endian()
    __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_ds_nn___pyx_t_15fused_redeclare_npy_uint8(object, int)
    __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_dsds_nn___pyx_t_15fused_redeclare_npy_uint8(object, int)
    __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_dsds_nn___pyx_t_15fused_redeclare_npy_uint16(object, int)
    ctypedef struct __Pyx_memviewslice:
        void *memview
    void __PYX_XDEC_MEMVIEW(__Pyx_memviewslice *, int have_gil)
    bint __pyx_memoryview_check(object)
    ctypedef unsigned char ___pyx_npy_uint8 "__pyx_t_15fused_redeclare_npy_uint8"
    ctypedef unsigned char ___pyx_npy_uint8 "__pyx_t_15fused_redeclare_npy_uint8"
    ctypedef unsigned short ___pyx_npy_uint16 "__pyx_t_15fused_redeclare_npy_uint16"

I think this is due to there being code for deduplicating integer types, but no code for deduplicating typedefs:

seen_int_dtypes = set()
for buffer_type in all_buffer_types:
dtype = buffer_type.dtype
if dtype.is_typedef:
#decl_code.putln("ctypedef %s %s" % (dtype.resolve(),
# self._dtype_name(dtype)))
decl_code.putln('ctypedef %s %s "%s"' % (dtype.resolve(),
if buffer_type.dtype.is_int:
if str(dtype) not in seen_int_dtypes:
cdef bint {{dtype_name}}_is_signed
{{dtype_name}}_is_signed = not (<{{dtype_type}}> -1 > 0)

@alex-xnor alex-xnor referenced a pull request that will close this issue Aug 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
1 participant
You can’t perform that action at this time.