Craig Citro wrote:
> I'm talking about a
> snippet like this:
>
> cdef void foo(object x):
> if isinstance(x, dict):
> x['spam'] = 5
>
> Is Pyrex smart enough to infer that x is in fact a dict, and emit a
> call to PyDict_GetItemString or the like?
No, it's not, but you can get the same effect by casting
the object to a dict:
cdef void foo(object x):
cdef dict d
if isinstance(x, dict):
d = <dict>x
d['spam'] = 5
Or if you don't care about type safety, you can skip the
type test and just do
cdef void foo(object x):
cdef dict d
d = <dict>x
d['spam'] = 5
--
Greg
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev