[pypy-dev] python 2 and python 3 sharing an interpreter?

holger krekel holger at merlinux.eu
Sat Dec 10 13:14:00 CET 2011


On Thu, Dec 08, 2011 at 05:35 -0500, Alex Gaynor wrote:
> On Thu, Dec 8, 2011 at 5:16 AM, Martijn Faassen <faassen at startifact.com>wrote:
> > Would it be possible to have an interpreter that could support both Python
> > 2 and Python 3 modules in the same runtime? I.e, an interpreter that
> > supports importing Python 3 code from Python 2 modules, and vice versa?
> >
> > It would tremendously help the Python ecosystem for such a solution to be
> > out there, because in such a situation people can start using Python 3
> > codebases in Python 2, encouraging more people to port their libraries to
> > Python 3, and people can use Python 2 codebases in Python 3, encouraging
> > more people to start projects in Python 3. I can't stress enough how much I
> > believe that would help the Python ecosystem!
> >
> 
> I don't think it can, or should be done, here's why:  Say you have a Python
> 2 dictionary {"a": 3}, and you pass this over to py3k land, what does it
> become?  Logically it becomes a {b"a": 3}, two problems: a) it now has
> bytes for keys, which means you can't use it as a **kwargs, b) internally
> ints have a totally different representation, since there's now only a
> unified long type (this one doesn't apply to pypy as much, just throwing it
> out there for completeness).  Python 2 fundamentally does the string type
> wrong, it's both the general string type for everythign, as well as the
> byte sequence, the result is no program has enough semantic knowledge to
> know what you mean by a string when you pass it over hte py3k boundary.

Alex, IIRC you were at Quora involved in a project connecting Python2
and pypy with execnet, right?  Do you agree that that connecting py3 and 
py2 should work just as well?  In any case, the execnet serializer
allows policies for passing strings/unicode between py2 and py3 (and the
execnet development branch contains even finer grained possibilities).

best,
holger


More information about the pypy-dev mailing list