Skip to content

docs: remove phantom parameters from two public docstrings (#2392) - #2493

Open
RerankerGuo wants to merge 1 commit into
MemTensor:dev-v2.0.36from
RerankerGuo:fix/issue-2392-docstring-phantoms
Open

RerankerGuo wants to merge 1 commit into
MemTensor:dev-v2.0.36from
RerankerGuo:fix/issue-2392-docstring-phantoms

Conversation

@RerankerGuo

Copy link
Copy Markdown
Contributor

Summary

Two public docstrings documented parameters that the AST no longer exposes.

AST-verified mismatches

  1. RedisPersistentUserManager.__init__(host, port, password, db, decode_responses) — the docstring’s Args section started with user_id (str, optional): User ID. Defaults to root., but user_id is not a parameter (it is a leftover from an earlier API). Dropped.
  2. concat_original_source(graph_results, rerank_source) — the docstring documented merge_field (List[str]), which is actually a local variable inside the function, and omitted the real rerank_source parameter (the comma-separated metadata field names that the function actually accepts). Rewrote the docstring with both parameters documented, with their actual semantics.

Regression guard

To prevent the same kind of drift from sneaking back in, this commit also adds tests/test_docstring_signature_parity.py. It parses each function’s source file (so it sees the real signature even when the function is wrapped by @require_python_package), extracts the parameter list from the AST, extracts the Args: block parameter names from the docstring, and asserts the two sets match. Any future divergence in either direction fails the test loudly.

Verification

PYTHONPATH=src pytest tests/test_docstring_signature_parity.py -v
============================== 2 passed in 5.97s ==============================

Ruff: ruff format --check and ruff check both clean on touched files (0 new findings vs main).

Out of scope

  • No new dependencies
  • No public API / OpenAPI contract changes
  • No DB schema, migration, or graph model changes
  • No Makefile / pyproject.toml / pre-commit / GitHub workflow changes
  • Docs-only

Closes #2392

…#2392)

Two public docstrings documented parameters that the AST no longer
exposes:

1. `RedisPersistentUserManager.__init__` listed `user_id (str, optional):`
   as the first Args entry, but the signature is `(host, port, password,
   db, decode_responses)` — `user_id` is a leftover from an earlier API.
   Removed the phantom line.

2. `concat_original_source` listed `merge_field (List[str]): List of fields
   to merge`, which is actually a local variable inside the function, and
   omitted the real `rerank_source` parameter (the comma-separated metadata
   field names that the function actually accepts). Rewrote the docstring
   with both `graph_results` and `rerank_source` documented, with their
   actual semantics.

To prevent the same kind of drift from sneaking back in, this commit also
adds tests/test_docstring_signature_parity.py: it parses each function's
source file, extracts the parameter list from the AST, extracts the
`Args:` block parameter names from the docstring, and asserts the two
sets match. The check works around the `@require_python_package`
decorator that rewrites `__code__`, so it sees the real `__init__`
signature rather than the wrapper's.

Docs-only functional change; the parity test is the regression guard.

Fixes MemTensor#2392.
@Memtensor-AI Memtensor-AI added area:core MOS 编排层 / 框架底座 / 跨模块问题 status:in-progress Someone or AI is working on it | 人工或 AI 正在处理 labels Oct 13, 2026
@Memtensor-AI

Copy link
Copy Markdown
Collaborator

🤖 Open Code Review

Target: PR #2493
Task: 72b97a5471fda697
Base: dev-v2.0.36
Head: fix/issue-2392-docstring-phantoms

🔍 OpenCodeReview found 2 issue(s) in this PR.


1. tests/test_docstring_signature_parity.py (L80-L81)

The AST lookup failing silently turns the parity check into a no-op. When node is None the signature set comes back empty, so only_in_sig is empty by construction and the first assertion can never fail; combined with _docstring_param_names also returning set() for any docstring that drops or reformats its Args: block (the repo mixes name (type): with name: str styles, e.g. truncate_data), both sets can be empty and the test reports success without having verified anything — the opposite of the "fail loudly" guarantee in the module docstring. Make the lookup failure explicit instead of degrading to an empty set.

💡 Suggested Change

Before:

    if node is None:
        return set()

After:

    if node is None:
        raise AssertionError(
            f"Could not locate an AST definition for {func.__qualname__} in {file_path}; "
            "docstring/signature parity was not actually verified"
        )

2. tests/test_docstring_signature_parity.py (L49-L52)

This module-scope fallback is unreachable: _function_def_in_class is only ever called from _signature_param_names, and only when len(qualname_parts) >= 2, so target_class is never None and the if target_class is not None: branch always returns first. The helper's docstring also claims it "falls back to module-scope search" for module functions, which cannot happen (module functions go through _function_def_for_module_func). Either drop the dead branch or make it genuinely reachable by moving the len(...) >= 2 dispatch inside the helper.

Generated by cloud-assistant via Open Code Review.

@Memtensor-AI

Copy link
Copy Markdown
Collaborator

✅ Automated Test Results: PASSED

All tests passed (2/2 executed). memos_python_core/changed-repo-python: 2/2. Duration: 9s

Branch: fix/issue-2392-docstring-phantoms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core MOS 编排层 / 框架底座 / 跨模块问题 status:in-progress Someone or AI is working on it | 人工或 AI 正在处理

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants