[Pyrex] [Cython-dev] cdef private class ... ?

Stefan Behnel stefan_ml at behnel.de
Tue Jan 29 08:59:58 CET 2008


Hi Greg,

Greg Ewing wrote:
> Stefan Behnel wrote:
>> I looked through the code to see how this would work. Apparently, all
>> cdef
>> types and cdef functions in Pyrex/Cython *are* "private" by default
>> (entry.visibility). But only classes are exported to Python space.
>> How's that for consistency!
> 
> The public/private distinction isn't about visibility to Python,
> it's about visibility to external C code.
> 
> Visibility to Python is determined by what kind of thing it is.
> C types and cdef functions only exist in the C world and are
> therefore not visible to Python. Def functions and extension types
> are Python objects, so they are visible to Python.

But the difference is that there is a way to make functions local (by
switching from 'def' to 'cdef'), but there isn't a way to make types local.

I just find it a bit of a bad design that 'cdef' changes the visibility in the
first case but not in the second. Basically, 'cdef' types behave like being
'cpdef'-ed, rather than 'cdef'-ed, while functions have a clean distinction here.


> It would be better to find another word for this distinction,
> such as 'hidden' or 'internal', if it's really desirable -- and
> I'm not yet convinced that it is.

I would really like to have something like this. In large modules, this helps
in uncluttering the module namespace. There really are cases where a user of
the module has no interest in being bothered with internal implementation
details of the 'module type space'.

Maybe we're back to the "del MyType" proposal then, which just removes the
name from the current scope. I think that would be the least intrusive, after
all, but also has an unclear interaction with Pyrex's global scoping rules.

Stefan




More information about the Pyrex mailing list