Going through machinations to satisfy PEP 8 makes no sense -- it's s style *guide* -- that's it.
-CHB On Tue, Feb 28, 2017 at 3:31 PM, Nicolas Cellier < cont...@nicolas-cellier.net> wrote: > I have seen some interest into lazy functionality implementation. > > I wondered if it can be linked with optional import. > > PEP 8 <http://www.python.org/dev/peps/pep-0008/> authoritatively states: > > Imports are always put at the top of the file, just after any module > comments and docstrings, and before module globals and constants. > > 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. > > Why not using the potential lazy keyword to have a nice way to deal with > it? > > For example: > > lazy import pylab as pl # do nothing for now >> >> # do stuff >> >> def plot(*args): >> pl.figure() # Will raise an ImportError at this point >> pl.plot(...) >> > > 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. > > _______________________________________________ > Python-ideas mailing list > Python-ideas@python.org > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/ > -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception chris.bar...@noaa.gov
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/