On Thu, Sep 7, 2017 at 11:46 AM, Erik Bray <erik.m.b...@gmail.com> wrote:
> On Thu, Sep 7, 2017 at 11:06 AM, Jeroen Demeyer <jdeme...@cage.ugent.be> 
> wrote:
>> On 2017-09-06 17:24, Erik Bray wrote:
>>>
>>> Interpreting
>>> "str" as "bytes" is the only way it can be if language_level=2.
>>
>>
>> I think you are misunderstanding. You didn't post the complete C code
>> generated by Cython:
>>
>>   __pyx_t_4 = __Pyx_PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_4))
>> __PYX_ERR(0, 2076, __pyx_L1_error)
>>   __Pyx_GOTREF(__pyx_t_4);
>>   __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2076,
>> __pyx_L1_error)
>>   __Pyx_GOTREF(__pyx_t_3);
>>   __Pyx_GIVEREF(__pyx_t_4);
>>   PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
>>   __pyx_t_4 = 0;
>>   __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)(&PyString_Type)), __pyx_t_3,
>> NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2076, __pyx_L1_error)
>>   __Pyx_GOTREF(__pyx_t_4);
>>   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
>>   __pyx_v_k = __pyx_t_4;
>>   __pyx_t_4 = 0;
>>
>> So, what this does is to interpret a char* as bytes, because a char* really
>> is just bytes. And then it calls str() on the result. So you get str(b"1").
>>
>> I don't think that this has anything to do with the language_level.
>
> Ah, you're right, I didn't see that I just saw the PyBytes_FromString.
> So it least "str" is really treated as "str" on Python 3. That's less
> terribly confusing than I thought.  I'd still like to play around with
> language_level=3 more though.  It still makes for a more consistent
> porting experience (e.g. string literals are unicode on Python 3).

Well, as was pointed out in #23089, this is definitely a non-starter
in the short term due to https://github.com/cython/cython/issues/1159
.  But I really think it's still the most sane approach in principle.
I'm going to work on that Cython issue--I agree it looks very tricky
but I don't think it's beyond solving and it really should be fixed...

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to