Stefan Behnel [26.11.2009 13:48]:
>> Lets look at the example that started this thread:
>>
>> cdef extern void c_foo(char*)
>>
>> def foo(str bar=""):
>>      c_foo(bar)
>>
>> Now I understand that your position that this is incorrect, broken,  
>> and fragile code just waiting to blow up in the users face, but from a  
>> pragmatic point of view it's working code that's part of a larger  
>> project and compiles and runs fine with Python 2 and Pyrex. It would  
>> compile and work fine with Cython as well except we have a check for  
>> just this case to disallow it [1], trying to force the user to write  
>> correct code.
>>     
>
> My position is that "str" is not the right type here. It's just like using
> "float" where "long" would be appropriate.
>   

Well, from the original posting it is stated that in Pyrex the above 
works nicely with text strings, which is what it is used for.

> If you want "bytes", write "bytes".

But I don't actually want bytes. Well, it's all bytes of course, but I 
want text strings. Something like Python-2.* 'str' or C++ std::string. 
The Python-3 semantics of 'bytes', in my opinion, deviates pretty much 
from what I consider a text string.

See my previous email:

code=b"ABC"
print(code[1])
66


I am pretty sure I don't want "text" strings like that. I rather have 
'str' everywhere and be forced to convert them before passing them to C/C++

code="ABC"
print(code[1])
'B'


is what I want and what I get in both Python 2 and 3 by using 'str'. And 
in both Python 2 and 3 I get

type("")
<type 'str'>

(well, almost). So I would expect that in Cython

def foo(str bar=""):

to be portable (which it is) and from thereon I need some conversion to 
get an ASCII representation of bar (provided that conversion is possible).

We may have started talking about different things, though. In my 
original email I made the mistake of redefining 'str', which in Cython 
is builtin, and this caused an unexpected collision of redefined str and 
"". In pure Cython as well as in Pyrex with proper definition of str

def foo(str bar=""):

does and will hopefully always work. So the issue here is really reduced 
to getting pure-ASCII strings in out of 'str' objects, which as a matter 
of fact depends on the encoding of str that is different in Python 2 and 
3. But that should be doable.

Cheers,
Joachim
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to