3 ms·
Import side effects are the devil and should be killed with fire wherever they appear.
by sdenton4 4y ago
Import side effects are the devil and should be killed with fire wherever they appear.
- Spivak 4y agoThe problem is that side effects are really broad and include things that are idiomatic Python. # jobs.py @scheduler.register_job(when=“daily”) def batch_job(): … This adds the job to the global scheduler. # models.py class Model(DBModel): def on_change(): # do stuff This adds the model to the ORM’s list of modules via a metaclasss and registers its hooks. # plugin.py class SomePlugin(PluginBase): … Same thing. The code to load plugins like this is just importing the module and letting the metaclass do the work.
- jonnycomputer 4y agoAmen