Skip to content

More user-friendly lazy imports

Terence Tsang requested to merge TTsangSC/gpaw:help-lazy-imports into master

(This builds upon !1173 (merged) and closes #1045 (closed).)

Motivation

Currently the gpaw.lazyimport() wrapper works perfectly for deferring the actual imports until the functions are actually called. However, they are completely opaque to end-users (without digging into the source code), and not so much as the import source (e.g. gpaw.calculator.GPAW -> gpaw.OldGPAW) can be retrieved.

Changes

  • The MR addresses this by migrating the lazy imports to the top-level module's .__getattr__(). The names are also made available publicly via a corresponding top-level .__dir__().
  • gpaw.lazyimport() and <import_wrapper>.import_now() no longer exist; references thereto are dropped from gpaw.__init__ and gpaw.cli.

Apropos

Regardless of this MR, seeing that !1173 (merged) has already been merged, should #1045 (closed) be closed anyways? Or is any further work needed?

Edited by Terence Tsang

Merge request reports