Supose you construct a dict with string keys on Cython code, and that
dict is intended to be used as a **kargs for calling some function.
Moreover, supose you construct such dict as a literal, and the keys
are also string literals... How can I write that in such a way that
works both in Py2 and Py3 without duplicating code? If you use b"abc"
for the keys, it does not work on Py3. If you use u"abc", it does not
work on Py2. If you use a bare "abc", it will work on Py2 or Py3 (but
not both) depending on "Future.unicode_literals".

In short, string literals are a big PITA, at least for me. And I
believe that other Cython users do not complain loudly just because
they do not have Py3 as a target runtime yet.

* All my Cython sources are ASCII (I even misspell my last name just
to maintain them pure ASCII).
* In all cases, my bare string literals (I mean, "abc") are pure ASCII.
* In the few cases I need a byte-string (to match PyBytes types in
Py3), I do use b"abc".

Why then cannot I have an option or compiler directive (or perhaps
just a global option) that will make bare "abc" string literals become
PyString in Py2 and PyUnicode in Py3?

Even if these literals were restricted to be pure-ASCII (Cython
generating a error if I write a bare "abcX" were X cannot be
ASCII-encoded), I would be more than happy.

Stefan, Can you imagine any potential problem with this? Please take
into account I'm not talking about the conversion Py <-> char*, just
(pure-ASCII) string literals with unspecified kind. Am I (once more)
missing something?



-- 
Lisandro Dalcín
---------------
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to