-
Notifications
You must be signed in to change notification settings - Fork 585
feat(plugin): enhance register method to support aliases for plugins #5162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -38,13 +38,17 @@ def __add__(self, other: "Plugin") -> "Plugin": | |||||||||||||||||||||||||||||||||||||||||||||||
| self.plugins.update(other.plugins) | ||||||||||||||||||||||||||||||||||||||||||||||||
| return self | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| def register(self, key: str) -> Callable[[object], object]: | ||||||||||||||||||||||||||||||||||||||||||||||||
| def register( | ||||||||||||||||||||||||||||||||||||||||||||||||
| self, key: str, alias: list[str] | None = None | ||||||||||||||||||||||||||||||||||||||||||||||||
| ) -> Callable[[object], object]: | ||||||||||||||||||||||||||||||||||||||||||||||||
| """Register a plugin. | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| Parameters | ||||||||||||||||||||||||||||||||||||||||||||||||
| ---------- | ||||||||||||||||||||||||||||||||||||||||||||||||
| key : str | ||||||||||||||||||||||||||||||||||||||||||||||||
| key of the plugin | ||||||||||||||||||||||||||||||||||||||||||||||||
| Primary key of the plugin. | ||||||||||||||||||||||||||||||||||||||||||||||||
| alias : list[str], optional | ||||||||||||||||||||||||||||||||||||||||||||||||
| Alternative keys for the plugin. | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| Returns | ||||||||||||||||||||||||||||||||||||||||||||||||
| ------- | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -54,6 +58,9 @@ def register(self, key: str) -> Callable[[object], object]: | |||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| def decorator(object: object) -> object: | ||||||||||||||||||||||||||||||||||||||||||||||||
| self.plugins[key] = object | ||||||||||||||||||||||||||||||||||||||||||||||||
| if alias: | ||||||||||||||||||||||||||||||||||||||||||||||||
| for alias_key in alias: | ||||||||||||||||||||||||||||||||||||||||||||||||
| self.plugins[alias_key] = object | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
60
to
+63
|
||||||||||||||||||||||||||||||||||||||||||||||||
| self.plugins[key] = object | |
| if alias: | |
| for alias_key in alias: | |
| self.plugins[alias_key] = object | |
| # Collect all keys (primary and aliases) to be registered | |
| keys_to_register: list[str] = [key] | |
| if alias: | |
| keys_to_register.extend(alias) | |
| # Validate that none of the keys are already registered | |
| for k in keys_to_register: | |
| if k in self.plugins: | |
| raise KeyError( | |
| f"Plugin key '{k}' is already registered and cannot be overwritten." | |
| ) | |
| # Register the plugin under all requested keys | |
| for k in keys_to_register: | |
| self.plugins[k] = object |
Copilot
AI
Jan 19, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The loop variable 'alias_key' creates potential confusion with the parameter 'alias'. Consider using a more descriptive variable name like 'alias_name' or 'key' to improve code clarity and avoid any naming ambiguity.
| for alias_key in alias: | |
| self.plugins[alias_key] = object | |
| for alias_name in alias: | |
| self.plugins[alias_name] = object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The alias registration logic doesn't validate whether an alias key already exists in the plugins dictionary. If an alias key is already registered (either as a primary key or another alias), it will be silently overwritten. Consider adding validation to check for key conflicts and either raise an error or log a warning to prevent unintended plugin overwrites.