[Core SDK] Duplicate nested `_plugin_name` helper in plugins/__init__.py shadows module-level helper

オープン
#5,253 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

  • #5255 @praisonai-triage-agent による — マージされずにクローズ

評価

難易度
1/5
見積もり時間
1時間未満
初心者へのやさしさ
50/100
issue の種類
リファクタリング
明瞭さ
明確に書かれている
活発さ
静か
技術スタック
python
領域
backend

調査の方向性

The shadowing copy is the nested _plugin_name inside enable() in praisonaiagents/plugins/init.py, around lines 194-198; the module-level helper at lines 94-104 is the one to keep, and disable() near line 269 already uses it. Read the closed, unmerged PR #5255 first to learn why it was rejected. Run tests/unit/plugins/test_plugins_enable.py and tests/unit/plugins/test_late_plugin_registration.py. Done means the nested definition is gone and those tests still pass.

索引モデルが issue の本文から書いたものです。

説明

claude documentation

Summary

praisonaiagents/plugins/__init__.py defines a nested _plugin_name() helper inside enable() that duplicates the module-level _plugin_name() already in scope. Removing the nested copy is a pure, behaviour-preserving de-duplication (and closes a small robustness divergence). This is not a feature change.

Current behaviour

Module-level helper — plugins/__init__.py:94-104:

def _plugin_name(plugin_info) -> str:
    """Read a plugin's name from a PluginInfo, or from a dict."""
    if isinstance(plugin_info, dict):
        return plugin_info.get("name", "")
    return getattr(plugin_info, "name", "") or ""

Nested duplicate inside enable() — plugins/__init__.py:194-198:

def _plugin_name(plugin_info):
    """Read a plugin name from either PluginInfo or legacy dict data."""
    if isinstance(plugin_info, dict):
        return plugin_info.get("name", "")
    return getattr(plugin_info, "name", "")

The nested definition shadows the module-level helper for the duration of enable(). disable() (plugins/__init__.py:269) already uses the module-level helper directly.

Why it matters

Maintenance. Two copies of the same helper have already drifted: the nested copy omits the module-level version's trailing or "" guard. A plugin object whose name attribute is None therefore returns None through enable()'s path but "" through disable()'s path — a subtle inconsistency for the exact edge case the module-level docstring was written to defend against. One helper removes the divergence.

Category

Duplicate

Capability preserved

  • enable() selective allow-list, enable()-all, and disable() behaviour all unchanged.
  • Both PluginInfo dataclass and legacy-dict shapes still accepted (the module-level helper already handles both).
  • Registration allow-list gating, hook wiring, and per-plugin option delivery untouched.

Proposed approach

Remove the nested def _plugin_name (dead code — the identically-named module-level helper is already in scope and is strictly more robust). Remove dead code only; no API or behaviour change.

Resolution sketch

# Before — enable() carries a nested shadow of the module-level helper
def enable(...):
    ...
    manager.set_registration_allow_list(target_plugins)

    def _plugin_name(plugin_info):
        if isinstance(plugin_info, dict):
            return plugin_info.get("name", "")
        return getattr(plugin_info, "name", "")

    if target_plugins is not None:
        ...
            name = _plugin_name(plugin_info)

# After — rely on the module-level helper (identical behaviour, adds the `or ""` guard)
def enable(...):
    ...
    manager.set_registration_allow_list(target_plugins)

    if target_plugins is not None:
        ...
            name = _plugin_name(plugin_info)   # module-level _plugin_name (lines 94-104)

Severity

Low

Validation

  • Both definitions traced; the module-level helper is already referenced by disable() (plugins/__init__.py:269) and remains in scope inside enable() once the shadow is removed.
  • Both are private (_-prefixed) — no public API surface affected.
  • tests/unit/plugins/test_plugins_enable.py and tests/unit/plugins/test_late_plugin_registration.py exercise the selective, all-plugins, and disable paths.
  • Confirmed not intentional robustness: the nested copy is the less robust of the two, so removing it cannot regress behaviour.

Keep unchanged

Plugin enable/disable semantics, selective allow-list gating, late-registration allow-list handling, hook-registry wiring, and per-plugin option (on_config) delivery.

主要言語
Python
スター
9.3k
フォーク
1.5k
平均マージ
1日 5時間
マージ済み PR(30日)
520

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

MervinPraison/PraisonAI のほかの issue

MervinPraison/PraisonAI の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。