Open Helveg opened 1 year ago
One point of discussion: We can't get rid of the module object manipulation as long as magical attributes need to be set directly on nest
, e.g. nest.resolution = 0.1
. If perhaps we group these attributes under another object, e.g. nest.kernel.resolution
, or nest.attributes.resolution
, then we can remove all of the module magic in favor of PEP562 module level __getattr__
and __dir__
.
Issue automatically marked stale!
Is your feature request related to a problem? Please describe. Users are very used to importing everything they need from the main namespace
import nest
then usingnest.X
. To enable thisnest
has always imported all of its submodules, to expose these references in the main module.In the past this has already caused some headaches with circular references, dynamic attributes, and code execution at import time. The fixes of which increased the complexity of the main module.
Initial tests during the hackathon also showed that there was about a 1s cost associated with
import nest
.The NEST codebase also doesn't follow PEP8 conventions of prefixing private modules with an underscore, so we're technically endorsing users to import
nest.ll_api
, ornest.lib.hl_api_spatial
. This means we promise to support them as stable public APIs and can't make any changes to any part of the organization of the NEST interface without technically introducing breaking major changes.Describe the solution you'd like
__all__
.import nest
would use theast
stdlib to retrieve the__all__
of each nest submodule, and creates a map between each exported member, and the module it should be loaded from.nest
module simplifies to implement just a__getattr__
,__setattr__
and__dir__
method.They will fulfill 2 mechanisms:__annotations__
ofnest
, and asserts that the total set of__all__
of the submodules and the kernal attributes all occur in the__annotations__
, enforcing that each public attribute gets a typehint.Additional context Initial tests showed that
import nest
was reduced to 8e-05 seconds. This is because no code except for__init__.py
will actually be accessed on import. On very slow filesystems like WSL this went up to 40ms.