[PATCHES] Build pytalloc for two Python versions at once, port to py3

Petr Viktorin pviktori at redhat.com
Mon Mar 16 05:14:42 MDT 2015

On 03/14/2015 10:17 AM, Andrew Bartlett wrote:
> On Fri, 2015-03-13 at 14:00 +0100, Petr Viktorin wrote:
>> I believe that it's impossible to do while still keeping things clear.
>> I did try, however, to keep the deviations from Python 3 minimal. Here
>> they are:
>> * PyStr (to use either PyUnicode or PyBytes depending on the version)
> Can't we code to the Python3 API, and have it map both to python2
> strings, either as raw bytes or pushing (presumed internal mapping) UTF8
> to UTF8?  (Yes, we really should use the unix charset, but these parts
> of samba without unix charset == utf8 is just broken).

Unfortunately, no. A lot of the Python 3 API is also available in Python 
2, and using it would bring Python 3 semantics to the Python 2 version.

Specifically, to use the py3 API we'd have to use PyUnicode for all 
human-readable strings.
That leaves two choices for py2 behavior:
- aliasing PyUnicode to PyString, which would not work where PyUnicode 
is also needed in Python 2. Not to mention that alasing an existing type 
to something else would be extremely confusing.
- using PyUnicode everywhere, which won't work either. Even if all of 
Samba's py2 code didn't care if it was getting str or unicode, things 
like tp_repr (repr() implementation) fail when you return unicode in py2.

Petr Viktorin

More information about the samba-technical mailing list