[Cython] [cython-users] Cython .pxd introspection: listing defined constants

Greg Ewing greg.ewing at canterbury.ac.nz
Mon Feb 21 22:46:22 CET 2011

Stefan Behnel wrote:
> The same argument could be brought up against 
> "cdef" vs. "def" (between which the semantic difference is *huge*)

There are a couple of differences:

- 'cdef' and 'def' look very different (at least to me) because
   they *start* with a different letter. Whereas 'cdef' and 'cpdef'
   both start and end with the same letter, maknig tehm mcuh eazier
   to conufse.

- There is much less semantic overlap betwen 'def' and 'cdef'. If
   you use the wrong one, you usually find out about it fairly
   quickly one way or another -- you get a syntax error (e.g.
   'def struct'), or something doesn't work the way you expected
   (e.g. a function you thought you had exposed doesn't show up
   in Python).

   It's possible to accidentally expose a function, but only if
   you declare it with an implicit return type, which I never do
   when writing what I intend to be a C function (this could
   perhaps be made illegal to further reduce the chances of such
   an error).

   Mistaken use of 'cpdef' on a C attribute, on the other hand,
   would very often pass silently.


More information about the cython-devel mailing list