Repository navigation
Python: Declare every lazy namespace export in its type stub - #9750
Naveen Chatlapalli (1aifanatic) wants to merge 1 commit into
Conversation
agent_framework.anthropic, .foundry and .orchestrations export names at runtime that their __init__.pyi stubs omit, and .hyperlight has no stub, so type checkers reject imports that work. Add the missing names, add a hyperlight stub, and test that every lazy namespace's _IMPORTS matches its stub. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟢 Approval recommended
The changes preserve runtime behavior, and the only remaining feedback is a minor test-helper organization issue.
1 open issue
What changed in this PR
This PR aligns Python’s lazy namespace type stubs with existing runtime exports, improving type-checker visibility without changing runtime behavior.
Changes:
- Add missing exports to the Anthropic, Foundry, and orchestrations stubs.
- Introduce the Hyperlight namespace stub.
- Add static regression coverage for stub existence, exported names, and source-package alignment without requiring optional connectors.
| File | Description |
|---|---|
python/packages/core/tests/core/test_namespace_stubs.py |
Checks lazy namespace exports against their stubs. |
python/packages/core/agent_framework/orchestrations/__init__.pyi |
Declares six missing orchestration exports. |
python/packages/core/agent_framework/hyperlight/__init__.pyi |
Adds typing declarations for all six namespace exports. |
python/packages/core/agent_framework/foundry/__init__.pyi |
Exports FoundryAgentOptions. |
python/packages/core/agent_framework/anthropic/__init__.pyi |
Exports RawClaudeAgent. |
Review effort: Balanced
| _PACKAGE_ROOT = Path(__file__).parents[2] / "agent_framework" | ||
|
|
||
|
|
||
| def _lazy_namespaces() -> list[Path]: |
There was a problem hiding this comment.
I've left these in the test module. My reading of that section is that it's about where shared helpers go: fixtures in conftest.py, other reusable helpers in an imported module rather than conftest.py. These three functions are only used by this file. That matches the existing pattern in this directory: 30 test_*.py modules under packages/core/tests/core define module-private helpers, including the closest sibling, test_docstrings.py (6 helpers). Happy to move them into a helper module if maintainers read the rule more strictly.

Motivation & Context
The
agent_framework.<namespace>modules re-export connector classes lazily through_IMPORTSand__getattr__. Each has an__init__.pyiso type checkers see the same names. Four of them have drifted:agent_framework.anthropicRawClaudeAgentagent_framework.foundryFoundryAgentOptionsagent_framework.orchestrationsBaseGroupChatOrchestrator,GroupChatResponseReceivedEvent,OrchestrationState,TerminationCondition,clean_conversation_for_handoff,create_completion_messageagent_framework.hyperlight__init__.pyiat all, so every export isAnyAll of these imports work at runtime. For example, the
RawClaudeAgentdocstring itself showsfrom agent_framework.anthropic import RawClaudeAgent. Onmain, pyright 1.1.408 rejects the first three groups with"RawClaudeAgent" is unknown import symbol(8 errors for the names above).Description & Review Guide
anthropic,foundryandorchestrationsstubs.agent_framework/hyperlight/__init__.pyi, following themontystub.packages/core/tests/core/test_namespace_stubs.py. For every namespace that declares_IMPORTS, it parses__init__.pyand__init__.pyiwithastand checks three things: the stub exists, its imports and__all__match_IMPORTS, and each name comes from the same distribution package. It needs no optional connector installed.Verification:
mainforanthropic,foundry,hyperlightandorchestrations, and passes for all 22 namespaces with this change.HyperlightCodeActProvidernow resolves to its class instead ofAny._IMPORTSname in every namespace resolves at runtime with all workspace packages installed.Related Issue
N/A - trivial change: the stubs are meant to mirror
_IMPORTS, and this adds the names they are missing without changing any runtime export.AI Assistance
AI assistance details: Claude Code helped find the drift by comparing each namespace's
_IMPORTSwith its stub, write the stub updates and test, and draft this description.Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.🤖 Generated with Claude Code