Issue #1192 wontfix

Do not use __import__ ?

Chris Beelby
created an issue

At line 457 of /cherrypy/lib/ there is the use of the __import__ built-in function.

The documentation for python 2 and 3 both seem to indicate that this function should not be used, it is only for advanced situations, and that instead importlib.import_module() should be used. See here or here

From the docs:

If you simply want to import a module (potentially within a package) by name, use importlib.import_module().

Comments (3)

  1. Jason R. Coombs

    Good suggestion. That seems reasonable, except that importlib isn't available on Python 3.1 or Python 2.6 or earlier. We would need to require importlib as a dependency on those Python versions or bundle it as a dependency.

    It used to be the case that CherryPy was pretty strict about requiring new dependencies. My understanding is that once cherrypy moves to chroot, it will be more open to requiring third-party libraries, but until that time, reliance on __import__, especially in the basic way it is used, is perfectly acceptable.

  2. Log in to comment