refactor: don't init config at class definition to allow custom config classes/argparser #1252
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes #1246
Summary
Python's default arguments are evaluated once when the function is defined. Config was instantiated at BaseRobyn class definition and init.py body. Call Config() only inside BaseRobyn, and if not None. At SubRouter, forward the config parameter.
For config.compile_rust_path, access from the class object, and unset to ensure compile_rust_path is called once per config object. Allows to write custom argument parsers without colliding with Config.parser.
This allows to pass implement alternative configs, for example:
PR Checklist
Please ensure that:
Pre-Commit Instructions:
High-level PR Summary
This PR refactors how the
Config
class is initialized in Robyn to fix a bug (#1246) related to Python's default argument evaluation behavior. Instead of initializing the config at class definition and in__init__.py
, it now initializes the config inside theBaseRobyn
class only when needed. This change enables users to implement custom config classes and argument parsers without colliding with the defaultConfig.parser
. The PR also ensures thatcompile_rust_path
is called only once per config object by unsetting it after use.⏱️ Estimated Review Time: 5-15 minutes
💡 Review Order Suggestion
robyn/__init__.py