[RFC] importing 'email' package on Python 3

Stefan Rusek stefan at rusek.org
Mon Aug 3 19:11:41 CDT 2009

On Fri, Jul 31, 2009 at 23:17, Alejandro Santos <alejolp at alejolp.com> wrote:

> Hi,
> I'd like to receive some feedback on the best way to import the email
> package to keep compatibility for Python 2.4, 2.5, 2.6 and Py3k.
> 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://selenic.com/pipermail/mercurial-devel/attachments/20090804/a28e18f4/attachment.htm 

More information about the Mercurial-devel mailing list