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

Aperta
#5,253 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

  • #5255 di @praisonai-triage-agent — chiusa senza merge

Valutazione

Difficoltà
1/5
Tempo stimato
Meno di un'ora
Idoneità per principianti
50/100
Tipo di issue
Refactoring
Chiarezza
Specificata chiaramente
Stato di attività
Tranquilla
Stack tecnologico
python
Ambito
backend

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Python
Stelle
9.3k
Fork
1.5k
Merge medio
1g 5h
PR unite (30g)
520

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di MervinPraison/PraisonAI

Tutte le issue di MervinPraison/PraisonAI

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.