Skip to content

Lazy config loading via Bot.start()#37

Merged
PenguinBoi12 merged 2 commits intomainfrom
lazy-config-loading
Apr 6, 2026
Merged

Lazy config loading via Bot.start()#37
PenguinBoi12 merged 2 commits intomainfrom
lazy-config-loading

Conversation

@PenguinBoi12
Copy link
Copy Markdown
Contributor

Previously, Bot required a config at instantiation time, forcing library users to have a config path available at import time. This made it awkward to define a bot as a module-level singleton — a common and natural pattern — without immediately binding it to a config file.

This PR removes config from Bot.__init__ and moves it to Bot.start(), so users can now define and decorate their bot freely at module level and defer config to whenever they actually run it.

Changes:

  • Bot.__init__ no longer accepts a config argument
  • Bot.start() now requires a Config instance or path string
  • _load_config is private since it's an implementation detail of start CLI updated to pass config through bot.start(settings.config)

Result: users can now define their bot as a clean singleton, decorate it freely, and let the runner handle the rest:

bot = Bot()

@bot.hook
async def on_ready():
    print("Ready!")
bot.run(config=Config(...))

... 

bot.run(config="config/bot.yaml")

@PenguinBoi12 PenguinBoi12 changed the title Lazy config loading aka do not load config at bot instanciation Lazy config loading via Bot.start() Apr 6, 2026
@PenguinBoi12 PenguinBoi12 force-pushed the lazy-config-loading branch 3 times, most recently from 561eb1b to 1659c11 Compare April 6, 2026 08:13
@PenguinBoi12 PenguinBoi12 force-pushed the lazy-config-loading branch from 1659c11 to 4537328 Compare April 6, 2026 08:52
Copy link
Copy Markdown
Contributor

@chrisdedman chrisdedman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you either add an example or update the current examples (or one example) to reflect this change?

@PenguinBoi12
Copy link
Copy Markdown
Contributor Author

PenguinBoi12 commented Apr 6, 2026

Could you either add an example or update the current examples (or one example) to reflect this change?

I did, there's an example in the description of the PR. The doc will be changed after it's merged.

I might have forgotten the readme tho and examples, I'll change them.

Copy link
Copy Markdown
Contributor

@chrisdedman chrisdedman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Copy link
Copy Markdown
Contributor

@chrisdedman chrisdedman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@PenguinBoi12 PenguinBoi12 merged commit 2af77f6 into main Apr 6, 2026
4 checks passed
@PenguinBoi12 PenguinBoi12 deleted the lazy-config-loading branch April 6, 2026 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants