Stefan Behnel wrote:
> Robert Bradshaw, 10.02.2010 06:47:
>
>> cdef extern from "foo.h" namespace "Foo::Bar":
>> int f(int)
>>
>> cdef extern from "..." namespace "A::B" as X:
>> int x(int)
>>
>> print X.x(5)
>>
>
> +1 for these two, the first meaning that the names get defined in the flat
> module namespace.
>
> I don't think automatic namespace injection makes sense for anything but
> namespaces that are already valid Python identifiers. Given that there's
> some magic to it, I'm all for leaving it out completely. The 'as' syntax is
> simple enough, readable, and makes it clear what happens.
>
> Also, the above will most likely appear in a (reusable) .pxd anyway. That
> makes the 'as' syntax less important as there's almost always an explicit
> namespace given by the .pxd file name and an additional import following in
> a .pyx file, which can then decide what to name the things in the code, and
> how to deal with naming collisions.
>
I'm fine with this as well.
And I want to note that the "as X" syntax is really a shortcut for
creating a new pxd file in a sub-package. It would be nice if that was
reflected in the implementation (i.e. use a new ModuleScope for "X",
don't introduce a new if-test everywhere.)
Basically:
foo.pxd:
ctypedef int footype
cdef extern from "foo.h" namespace "A::B" as X: ...
is virtually transformed into
foo/
__init__.pxd:
"""
ctypedef int footype
"""
X.pxd:
"""
cdef extern from "foo.h" namespace "A::B": # note no as X
...
"""
Corollary: If "as X" appears in the namespace-as clause in an
__init__.pxd, then there can be no X.pxd or X.pyx in the same directory.
Dag Sverre
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev