Skip to content

fix: stop __version__ drift (#85) and mypy [no-redef] in optional mcp import (#87)#100

Merged
dgenio merged 3 commits into
mainfrom
claude/github-issues-triage-gYbqA
May 29, 2026
Merged

fix: stop __version__ drift (#85) and mypy [no-redef] in optional mcp import (#87)#100
dgenio merged 3 commits into
mainfrom
claude/github-issues-triage-gYbqA

Conversation

@dgenio

@dgenio dgenio commented May 28, 2026

Copy link
Copy Markdown
Owner

Fixes #85 and #87 — the two remaining infra/correctness defects from the #85#88 triage batch (the other two, #86 and #88, were already fixed in d83609d).

What changed

#85agent_kernel.__version__ drifted from pyproject.toml

  • src/agent_kernel/__init__.py: __version__ is now derived from installed distribution metadata via importlib.metadata.version("weaver-kernel") (single source of truth), with a PackageNotFoundError"0.0.0+local" fallback for source trees without dist metadata. The hardcoded "0.5.0" literal is gone.
  • tests/test_version.py (new): asserts __version__ == importlib.metadata.version("weaver-kernel") and that __version__ stays in __all__.

#87 — optional McpError import triggered mypy [no-redef] when mcp was absent

  • src/agent_kernel/drivers/mcp.py: replaced the annotate-then-import ... as _McpError pattern with a _load_mcp_error() helper that imports through importlib.import_module (mirroring the existing mcp_support.import_optional idiom). _McpError is now declared exactly once, so the [no-redef] is gone.
  • tests/test_mcp_driver.py: added two regression tests covering both branches of _load_mcp_error (mcp present → returns McpError; mcp absent → returns None).

Docs

Why

How verified

All commands run in a clean dev venv (pip install -e ".[dev,mcp]"):

Scope notes (Mode B)

Strictly limited to #85 and #87. Diffstat: 5 files, +62/−10 (4 tracked + 1 new test). No back-compat shims (per request — none needed; both are internal/diagnostic surfaces). Other open triage issues (#92#96, #99, #94) are independent feature/docs work and intentionally not bundled here.

Risks / caveats

  • importlib.metadata.version() must use the distribution name (weaver-kernel), not the import name (agent_kernel) — handled and covered by test_version.py. In an uninstalled raw source tree the value is 0.0.0+local; in editable/CI installs it reflects the real dist version.

https://claude.ai/code/session_0185WabrTuoL3jCNZiER7ES6


Generated by Claude Code

Two remaining infra fixes from the #85-#88 batch (#86/#88 already merged
in d83609d).

- #85: derive agent_kernel.__version__ from installed distribution
  metadata (importlib.metadata.version("weaver-kernel")) instead of a
  hardcoded literal that had drifted to "0.5.0" while the package shipped
  0.7.0/0.8.0. Falls back to "0.0.0+local" without dist metadata. This
  matches RELEASE.md, which only ever documented bumping pyproject.toml.
- #87: resolve the optional McpError import through a _load_mcp_error()
  helper (mirroring mcp_support.import_optional) so the _McpError global
  is declared exactly once, fixing the mypy [no-redef] that surfaced when
  the mcp extra was not installed.

Adds regression tests (tests/test_version.py; two _load_mcp_error cases in
tests/test_mcp_driver.py) and CHANGELOG entries. make ci passes
(564 passed, 1 skipped; mypy clean with and without the mcp extra).

https://claude.ai/code/session_0185WabrTuoL3jCNZiER7ES6
Copilot AI review requested due to automatic review settings May 28, 2026 22:28

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes two infra/correctness issues: preventing agent_kernel.__version__ from drifting from the packaged distribution version, and removing a mypy [no-redef] error caused by an optional mcp import pattern.

Changes:

  • Derive agent_kernel.__version__ from importlib.metadata.version("weaver-kernel") with a local fallback when dist metadata is unavailable.
  • Refactor optional McpError loading into a _load_mcp_error() helper to avoid mypy redefinition errors.
  • Add regression tests and document both fixes in the changelog.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/test_version.py New tests pin __version__ to distribution metadata and ensure it remains exported.
tests/test_mcp_driver.py Adds regression tests for _load_mcp_error() when mcp is present vs missing.
src/agent_kernel/drivers/mcp.py Introduces _load_mcp_error() and resolves _McpError once to avoid mypy [no-redef].
src/agent_kernel/init.py Replaces hardcoded __version__ with importlib.metadata-derived version + fallback.
CHANGELOG.md Adds Unreleased “Fixed” entries for issues #85 and #87.

Comment thread src/agent_kernel/drivers/mcp.py Outdated
claude added 2 commits May 29, 2026 06:55
Address PR review feedback: _load_mcp_error accessed exceptions.McpError
directly, so a module that imports but lacks/renames McpError would raise
AttributeError at import time and break agent_kernel.drivers.mcp entirely.
Use getattr(..., None) plus a type check to degrade to None, restoring the
old ImportError -> None fallback semantics for the optional-dependency path.

Add a regression test covering the module-present-but-attribute-missing case.

https://claude.ai/code/session_01TnKC4bmhsCCJTju77jKwdJ
Audit follow-up (#85 AC1): the existing test only re-derived __version__
from the same importlib.metadata source it is defined from, so it could not
catch a pyproject bump that the installed/editable metadata had not picked
up. Add test_version_matches_pyproject_declaration, which parses
[project].version directly (regex, no tomllib so it runs on 3.10) and skips
gracefully when the source tree is absent.

https://claude.ai/code/session_01TnKC4bmhsCCJTju77jKwdJ
@dgenio dgenio merged commit 22358d5 into main May 29, 2026
4 checks passed
@dgenio dgenio deleted the claude/github-issues-triage-gYbqA branch May 29, 2026 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

agent_kernel.__version__ reports "0.5.0" but pyproject.toml declares 0.7.0

3 participants