[RFC] importing 'email' package on Python 3

Martin Geisler mg at lazybytes.net
Tue Aug 4 15:33:07 CDT 2009


Stefan Rusek <stefan at rusek.org> writes:

> On Fri, Jul 31, 2009 at 23:17, Alejandro Santos <alejolp at alejolp.com> wrote:
>
>> Option 1: Use a try:/except ImportError: block, and use a Py2.4 alias:
>>
>> # See patchbomb.py
>> try: # Py2.5+, Py3k
>>    import email.mime.multipart as MIMEMultipart
>>    import email.mime.base as MIMEBase
>>    import email.utils as Utils
>>    import email.encoders as Encoders
>>    import email.generator as Generator
>> except ImportError: # Py2.4
>>    import email.MIMEMultipart as MIMEMultipart
>>    import email.MIMEBase as MIMEBase
>>    import email.Utils as Utils
>>    import email.Encoders as Encoders
>>    import email.Generator as Generator
>>
>> This alternative goes against coding style (Uppercase, CamelCase),
>> but is the least intrusive to the actual codebase.
>>
>> Option 2: Similar as before, using a lowercase convention and the
>> 'email' prefix to reduce at some degree name colissions:
>>
>> try: # Py2.5+, Py3k
>>    import email.mime.multipart as emailmimemultipart
>>    import email.utils as emailutils # Don't confuse with mercurial.util
>> except ImportError: # Py2.4
>>    import email.MIMEMultipart as emailmimemultipart
>>    import email.Utils as emailutils
>
> I realize this requires a bigger change to the extension than Option
> 1, but I think it is better since it will be less confusing when
> people unfamiliar with the code look at it, since it follows current
> and future naming conventions, and uses the current and future names
> for the modules, which improves understandability.

Personally, I don't think emailmimemultipart is readable at all.

Importing the new names and renaming them to Python 2.4 names (option 1)
seems the easiest and most readable to me -- when Mercurial drops
support for Python 2.4, we can switch to the new names.

-- 
Martin Geisler

VIFF (Virtual Ideal Functionality Framework) brings easy and efficient
SMPC (Secure Multiparty Computation) to Python. See: http://viff.dk/.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://selenic.com/pipermail/mercurial-devel/attachments/20090804/4e9d79f4/attachment.pgp 


More information about the Mercurial-devel mailing list