Dag Sverre Seljebotn wrote:
> Stefan Behnel wrote:
>> Dag Sverre Seljebotn wrote:
>>> a) Auto-cimport (if a directive is set, which defaults to on?). I.e. if
>>> you do a Python import, and a pxd file can be found, a cimport is done
>>> automatically.
>> +0.7 given that this may really have a performance impact, as Robert
>> stated. There should at least be a cache for the standard include path that
>> survives multiple compilations in one compiler run (another orthogonal
>> feature that would be nice for .pxd files in general).
>
> with cython.nopxd:
> import mymodule
>
> ?
-1
Besides being the wrong way round (most Python modules do not have a .pxd
file), this is clearly something that Cython should handle behind the
scenes. User code shouldn't be impacted by it. If anything, a compiler
option would fit. But thinking about that now smells like a premature
optimisation to me.
>>> b) Overloading combined with fall-through to Python space. I started a
>>> CEP on this [1], Robert discussed it with me, but it never got finished.
>>>
>>> One way is to allow e.g. (in "math.pxd")
>>>
>>> double sin(double x): return libc.math.sin(x)
>>> object sin(object x)
>> +1, nice feature.
>>
>>
>>> Somehow it must be added here though that sin should be looked up at
>>> module initialization using getattr rather than through
>>> __pyx_capi/Cython call convention.
>> That would be implied by the fact that you used a Python import. But
>> leaving this to the poor importer might turn out to be error prone, given
>> that the math module actually is a C extension...
>
> -1 on leaving it to importer; I'd like to use "import" to cimport Cython
> extensions too! Lower learning curve etc.
Fine.
> This could actually be done at runtime. Support code:
>
> static PyObject* math_sin_looked_up_with_getattr = NULL;
>
> static PyObject* math_sin_with_getattr(PyObject* obj) {
> /* call math_sin_looked_up_with_getattr using CPython API */
> }
>
> In module initialization:
>
> if hasattr(math module, "__pyx_capi"):
> set math_sin as today
> else:
> look up and set math_sin_looked_up_with_getattr
> set math_sin to math_sin_with_getattr
>
> Then, call math_sin as today in general.
>
> The minus is that it blows up code size somewhat for cimported Cython
> modules; new syntax would avoid that.
I'm more for avoiding new syntax. Lower learning curve etc. ;)
I think it's a good idea to simply generate code like this and to leave the
import handling entirely to runtime code. Note that only functions that are
pure Python functions need to be looked up at the module level. Everything
else must be imported from __pyx_capi and a failure to do so is fatal.
All ambiguous imports should then get imported from __pyx_capi one by one,
and failing to do so, get imported from the module dict next. A failure to
import from both is fatal again. Note that this allows names to get
imported from either source on a case-by-case basis.
Stefan
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev