On Wed, Sep 6, 2017 at 5:13 PM, Jeroen Demeyer <jdeme...@cage.ugent.be> wrote: > On 2017-09-06 17:05, Erik Bray wrote: >> >> "language level 2" [...], where "str" means "bytes". > > > [citation needed] > > Where did you get the idea that Cython interprets "str" as "bytes" with > Python 3? > > In https://trac.sagemath.org/ticket/23089 I argued *against* changing the > Cython language_level.
It's pretty clear about that in the docs: http://cython.readthedocs.io/en/latest/src/tutorial/strings.html#python-string-types-in-cython-code This makes sense because there is no equivalent to Python 2 "str" in Python 3. The nearest equivalent is Python 3 "bytes". Interpreting "str" as "bytes" is the only way it can be if language_level=2. So for example with language_level=2 you get conversions like: 19832 /* "sage/rings/rational.pyx":2075 19833 * sig_on() 19834 * mpq_get_str(s, base, self.value) 19835 * sig_off() # <<<<<<<<<<<<<< 19836 * k = str(s) 19837 * PyMem_Free(s) 19838 */ 19839 sig_off(); 19840 19841 /* "sage/rings/rational.pyx":2076 19842 * mpq_get_str(s, base, self.value) 19843 * sig_off() 19844 * k = str(s) # <<<<<<<<<<<<<< 19845 * PyMem_Free(s) 19846 * return k 19847 */ 19848 __pyx_t_4 = __Pyx_PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_4 )) __PYX_ERR(0, 2076, __pyx_L1_error) So this causes Rational.__repr__ to return a bytes instead of a str. Ick. I'll have to look at your argument against it. I actually didn't know about language_level until now--I had assumed that if you Cython on Python 3 it's going to be nearer to Python 3 in terms of semantics. But I think it makes enormous sense to set the correct language_level for the Python in use, otherwise writing 2/3 code requires different idioms when moving between Python and Cython code and that's a recipe for headaches. -- 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.