Hacker News new | past | comments | ask | show | jobs | submit login

Import side effects are the devil and should be killed with fire wherever they appear.



The 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.


Amen




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: