[Cython] Fused Types
stefan_ml at behnel.de
Tue Apr 26 22:02:24 CEST 2011
mark florisson, 26.04.2011 17:18:
> On 26 April 2011 16:43, Stefan Behnel wrote:
>> mark florisson, 26.04.2011 16:23:
>>> I've been working a bit on fused types
>>> (http://wiki.cython.org/enhancements/fusedtypes), and I've got it to
>>> generate code for every permutation of specific types. Currently it
>>> only works for cdef functions. Now in SimpleCallNode I'm trying to use
>>> PyrexTypes.best_match() to find the function with the best signature,
>>> but it doesn't seem to take care of coercions, e.g. it calls
>>> 'assignable_from' on the dst_type (e.g. char *), but for
>>> BuiltinObjectType (a str) this returns false.
>> Which is correct. "char*" cannot coerce from/to "str". It can coerce to
>> "bytes", though.
> Right, I see, so the thing is that I was using string literals which
> should be inferred as the bytes type when they are assigned to a char
> *. The thing is that because the type is fused, the argument may be
> anything, so I was hoping best_match would figure it out for me.
> Apparently it doesn't, and indeed, this example doesn't work:
> cdef extern from "Foo.h":
> cdef cppclass Foo:
> Foo(char *)
> cdef char *foo = "foo"
> cdef Foo* foo = new Foo("foo") #<- this doesn't work ("no suitable
> method found")
> cdef Foo* bar = new Foo(foo) #<- this works
> So that's pretty lame, I think I should fix that.
Well, I assume it's less lame when you use b"foo". But given the current
auto-coerce semantics for unprefixed string literals in Cython, I agree
that it should also auto-coerce here.
More information about the cython-devel