<div dir="ltr"><div>Going through machinations to satisfy PEP 8 makes no sense -- it's s style *guide* -- that's it.<br><br></div>-CHB<br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Feb 28, 2017 at 3:31 PM, Nicolas Cellier <span dir="ltr"><<a href="mailto:contact@nicolas-cellier.net" target="_blank">contact@nicolas-cellier.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>I have seen some interest into lazy functionality implementation.<br><br></div>I wondered if it can be linked with optional import.<br><div class="m_-7748567276886954481gmail-m_-2113992186940316494gmail-post-text">
<p><a href="http://www.python.org/dev/peps/pep-0008/" rel="noreferrer" target="_blank">PEP 8</a> authoritatively states:</p>

<blockquote><div>
  <p>Imports are always put at the top of
  the file, just after any module
        comments and docstrings, and before module globals and constants.</p></div></blockquote>So, if we want to stick to PEP8 with non mandatory import, we have to catch the import errors, or jail the class or function using extra functionnality.<br><br></div><div class="m_-7748567276886954481gmail-m_-2113992186940316494gmail-post-text">Why not using the potential lazy keyword to have a nice way to deal with it?<br><br></div><div class="m_-7748567276886954481gmail-m_-2113992186940316494gmail-post-text">For example:<br><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>lazy import pylab as pl  # do nothing for now<br><br></div><div># do stuff<br><br></div><div>def plot(*args):<br></div><div>    pl.figure() # Will raise an ImportError at this point<br></div><div>    pl.plot(...)<br></div></blockquote><div><br></div><div>That way, our library will raise an ImportError only on plot func usage with an explicit traceback : if matplotlib is not installed, we will have the line where it is used for the first time and we will have the name of the faulty library.<br></div></div>
<br>______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/<wbr>codeofconduct/</a><br></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><br>Christopher Barker, Ph.D.<br>Oceanographer<br><br>Emergency Response Division<br>NOAA/NOS/OR&R            (206) 526-6959   voice<br>7600 Sand Point Way NE   (206) 526-6329   fax<br>Seattle, WA  98115       (206) 526-6317   main reception<br><br><a href="mailto:Chris.Barker@noaa.gov" target="_blank">Chris.Barker@noaa.gov</a></div>
</div>