Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

FunctionManager silently drops tool modules containing dataclasses with postponed annotations

未关闭
#681 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
72/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
tooling

调研方向

Start with utils/function_manager.py and reproduce the temporary tool module containing postponed annotations and a dataclass. Run python reproduce.py --fetch --case chatdev-dataclass-tools --variant after from the linked bundle to inspect the seven regression and control tests. Done means increment is available and failed imports clean up or restore module state while existing filtering remains intact.

由索引模型根据 Issue 内容生成。

描述

Problem

The dynamic loader creates a module with module_from_spec() and executes it without inserting it into sys.modules. A tool file containing from __future__ import annotations and a dataclass then fails during class creation, because the dataclass decorator needs to resolve the defining module.

FunctionManager catches the import failure and omits the module's functions, so otherwise valid agent tools become unavailable.

Reproduction

import tempfile
from pathlib import Path
from utils.function_manager import FunctionManager

with tempfile.TemporaryDirectory() as directory:
    path = Path(directory) / 'example.py'
    path.write_text('''from __future__ import annotations
from dataclasses import dataclass

@dataclass
class Payload:
    value: int

def increment(value: int) -> int:
    return Payload(value).value + 1
''', encoding='utf-8')
    manager = FunctionManager(Path(directory))
    print(manager.has_function('increment'))  # Actual: False; expected: True
    print(manager.call_function('increment', 41))  # Expected: 42

Proposed change

Register the new module in sys.modules[module_name] before exec_module(). On an import failure, remove the partially initialized module or restore the previous entry, then re-raise into the existing loader error handling. This follows normal import semantics while preserving the current filtering of private and imported functions.

Validation

Source: utils/function_manager.py, current blob 50de030442ec72e8293482320cc37072367c86cd.

Before: 4 failed, 3 passed. After: 7 passed. The complete FunctionManager module was run against real temporary tool files, including postponed-annotation dataclasses, self-referential annotations, ordinary tools, imported/private function filtering, failed-import cleanup, and restoration after a failed reload.

Python 3.13.5, pytest 9.0.2, Linux. No provider calls or full workflow execution were run. Searches for FunctionManager issues and dataclass-related PRs found memory-store additions, not this dynamic-import failure.

Patch and tests

Source-pinned patch and seven regression/control tests. From the bundle root, run python reproduce.py --fetch --case chatdev-dataclass-tools --variant after. The runner verifies the source hash and patch application before executing the tests.

主要语言
Python
星标
34.4k
派生
4.3k
PR 合并指标
30 天内没有已合并 PR

环境准备

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

OpenBMB/ChatDev 的其他 Issue

查看 OpenBMB/ChatDev 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。