[Python] Remove copilot.types#871
Conversation
Along the way, simplify `copilot.__init__` to only export the high-level API.
There was a problem hiding this comment.
Pull request overview
Removes the Python copilot.types module and redistributes its type definitions across the more appropriate modules (copilot.client, copilot.session, copilot.tools), while simplifying copilot.__init__ to only expose the high-level API surface.
Changes:
- Deleted
python/copilot/types.pyand moved type definitions intopython/copilot/client.py,python/copilot/session.py, andpython/copilot/tools.py. - Simplified
python/copilot/__init__.pyexports to only includeCopilotClient,CopilotSession, connection configs, anddefine_tool. - Updated imports across scenarios, tests, samples, and docs to use the new module locations.
Reviewed changes
Copilot reviewed 67 out of 67 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| test/scenarios/transport/tcp/python/main.py | Update imports to new type locations. |
| test/scenarios/transport/stdio/python/main.py | Update imports to new type locations. |
| test/scenarios/transport/reconnect/python/main.py | Update imports to new type locations. |
| test/scenarios/tools/virtual-filesystem/python/main.py | Update imports to new type locations. |
| test/scenarios/tools/tool-overrides/python/main.py | Update imports to new type locations. |
| test/scenarios/tools/tool-filtering/python/main.py | Update imports to new type locations. |
| test/scenarios/tools/skills/python/main.py | Update imports to new type locations. |
| test/scenarios/tools/no-tools/python/main.py | Update imports to new type locations. |
| test/scenarios/tools/mcp-servers/python/main.py | Update imports to new type locations. |
| test/scenarios/tools/custom-agents/python/main.py | Update imports to new type locations. |
| test/scenarios/sessions/streaming/python/main.py | Update imports to new type locations. |
| test/scenarios/sessions/session-resume/python/main.py | Update imports to new type locations. |
| test/scenarios/sessions/infinite-sessions/python/main.py | Update imports to new type locations. |
| test/scenarios/sessions/concurrent-sessions/python/main.py | Update imports to new type locations. |
| test/scenarios/prompts/system-message/python/main.py | Update imports to new type locations. |
| test/scenarios/prompts/reasoning-effort/python/main.py | Update imports to new type locations. |
| test/scenarios/prompts/attachments/python/main.py | Update imports to new type locations. |
| test/scenarios/modes/minimal/python/main.py | Update imports to new type locations. |
| test/scenarios/modes/default/python/main.py | Update imports to new type locations. |
| test/scenarios/callbacks/user-input/python/main.py | Update imports to new type locations. |
| test/scenarios/callbacks/permissions/python/main.py | Update imports to new type locations. |
| test/scenarios/callbacks/hooks/python/main.py | Update imports to new type locations. |
| test/scenarios/bundling/fully-bundled/python/main.py | Update imports to new type locations. |
| test/scenarios/bundling/container-proxy/python/main.py | Update imports to new type locations. |
| test/scenarios/bundling/app-direct-server/python/main.py | Update imports to new type locations. |
| test/scenarios/bundling/app-backend-to-server/python/main.py | Update imports to new type locations. |
| test/scenarios/auth/gh-app/python/main.py | Update imports to new type locations. |
| test/scenarios/auth/byok-openai/python/main.py | Update imports to new type locations. |
| test/scenarios/auth/byok-ollama/python/main.py | Update imports to new type locations. |
| test/scenarios/auth/byok-azure/python/main.py | Update imports to new type locations. |
| test/scenarios/auth/byok-anthropic/python/main.py | Update imports to new type locations. |
| python/test_telemetry.py | Import Telemetry/Subprocess config types from copilot.client. |
| python/test_client.py | Update imports to copilot.client / copilot.session; stop using copilot.types. |
| python/samples/chat.py | Import PermissionHandler from copilot.session. |
| python/e2e/testharness/context.py | Import SubprocessConfig from copilot.client. |
| python/e2e/test_tools_unit.py | Import tool types directly from copilot.tools. |
| python/e2e/test_tools.py | Import session/tool types from their new modules. |
| python/e2e/test_streaming_fidelity.py | Import session/client types from their new modules. |
| python/e2e/test_skills.py | Import PermissionHandler from copilot.session. |
| python/e2e/test_session.py | Import Tool/ToolResult from copilot.tools; session types from copilot.session. |
| python/e2e/test_rpc.py | Import SubprocessConfig from copilot.client and PermissionHandler from copilot.session. |
| python/e2e/test_permissions.py | Import permission types from copilot.session. |
| python/e2e/test_multi_client.py | Import session/tool/client types from their new modules. |
| python/e2e/test_mcp_and_agents.py | Import MCP/agent/session types from copilot.session. |
| python/e2e/test_hooks.py | Import PermissionHandler from copilot.session. |
| python/e2e/test_compaction.py | Import PermissionHandler from copilot.session. |
| python/e2e/test_client.py | Import StopError/SubprocessConfig from copilot.client; permission handler from copilot.session. |
| python/e2e/test_ask_user.py | Import PermissionHandler from copilot.session. |
| python/e2e/test_agent_and_compact_rpc.py | Import SubprocessConfig from copilot.client; permission handler from copilot.session. |
| python/copilot/types.py | Removed legacy centralized types module. |
| python/copilot/tools.py | Inlines Tool-related dataclasses previously in copilot.types. |
| python/copilot/session.py | Inlines session-related config/handler/attachment types previously in copilot.types. |
| python/copilot/client.py | Inlines client/connection/config/model/metadata types previously in copilot.types. |
| python/copilot/init.py | Restricts root exports to high-level API and connection configs. |
| python/README.md | Update Tool import to copilot.tools. |
| docs/setup/azure-managed-identity.md | Update Provider/Session config imports to copilot.session. |
| docs/hooks/user-prompt-submitted.md | Update type imports to copilot.session (but Python snippet still references HookInvocation). |
| docs/hooks/session-lifecycle.md | Update type imports to copilot.session (but Python snippets still reference HookInvocation / mismatched return types). |
| docs/hooks/pre-tool-use.md | Update type imports to copilot.session (but Python snippet still references HookInvocation). |
| docs/hooks/post-tool-use.md | Update type imports to copilot.session (but Python snippet still references HookInvocation). |
| docs/hooks/error-handling.md | Update type imports to copilot.session (but Python snippet still references HookInvocation). |
| docs/getting-started.md | Update PermissionHandler import to copilot.session. |
| docs/features/steering-and-queueing.md | Update PermissionRequestResult import to copilot.session. |
| docs/features/skills.md | Update PermissionRequestResult import to copilot.session. |
| docs/features/image-input.md | Update PermissionRequestResult import to copilot.session. |
| docs/features/custom-agents.md | Update PermissionRequestResult import to copilot.session. |
| docs/auth/byok.md | Update model-type imports to copilot.client. |
Comments suppressed due to low confidence (6)
docs/hooks/user-prompt-submitted.md:44
- In the Python hook signature snippet,
HookInvocationis referenced but is no longer imported/defined after switching away fromcopilot.types. This will make the docs-validated code block fail. Either import aHookInvocationalias (e.g., fromcopilot.sessionif added) or update the signature to use the actual invocation type used by the SDK (currently adict[str, str]).
from copilot.session import UserPromptSubmittedHookInput, UserPromptSubmittedHookOutput
from typing import Callable, Awaitable
UserPromptSubmittedHandler = Callable[
[UserPromptSubmittedHookInput, HookInvocation],
Awaitable[UserPromptSubmittedHookOutput | None]
]
docs/hooks/pre-tool-use.md:44
- The Python docs-validated snippet still uses
HookInvocationin the handler type but it is no longer imported/defined after the import change. This will break docs validation; either defineHookInvocationlocally (or export it fromcopilot.session) or change the signature to the SDK’s invocation type (dict[str, str]).
from copilot.session import PreToolUseHookInput, PreToolUseHookOutput
from typing import Callable, Awaitable
PreToolUseHandler = Callable[
[PreToolUseHookInput, HookInvocation],
Awaitable[PreToolUseHookOutput | None]
]
docs/hooks/post-tool-use.md:44
- The Python hook signature references
HookInvocationbut it is no longer imported/defined after switching the import tocopilot.session. This makes the docs-validated code block invalid; import/defineHookInvocation(or usedict[str, str]to match the SDK).
from copilot.session import PostToolUseHookInput, PostToolUseHookOutput
from typing import Callable, Awaitable
PostToolUseHandler = Callable[
[PostToolUseHookInput, HookInvocation],
Awaitable[PostToolUseHookOutput | None]
]
docs/hooks/error-handling.md:44
- The Python hook signature still uses
HookInvocation, but the updated import line no longer imports it (and it isn’t defined in the snippet). This will fail docs validation; either add/defineHookInvocationor update the signature to use the actual invocation type (dict[str, str]).
from copilot.session import ErrorOccurredHookInput, ErrorOccurredHookOutput
from typing import Callable, Awaitable
ErrorOccurredHandler = Callable[
[ErrorOccurredHookInput, HookInvocation],
Awaitable[ErrorOccurredHookOutput | None]
]
docs/hooks/session-lifecycle.md:48
- In the Python SessionStart handler snippet,
HookInvocationis referenced but not imported/defined after the import change. This will break docs validation; either import/define aHookInvocationalias or update the signature to usedict[str, str](which matches the SDK’s hook invocation parameter).
from copilot.session import SessionStartHookInput, SessionStartHookOutput
from typing import Callable, Awaitable
SessionStartHandler = Callable[
[SessionStartHookInput, HookInvocation],
Awaitable[SessionStartHookOutput | None]
]
docs/hooks/session-lifecycle.md:265
- In the Python SessionEnd handler snippet,
HookInvocation(andSessionEndHookOutputin the visible block) are referenced but not imported/defined. Additionally, the hidden and visible blocks show different return types. This is likely to fail docs validation; align both blocks and ensure all referenced types are imported/defined (or usedict[str, str]for the invocation parameter).
from copilot.session import SessionEndHookInput
from typing import Callable, Awaitable
SessionEndHandler = Callable[
[SessionEndHookInput, HookInvocation],
Awaitable[None]
]
SessionEndHandler = Callable[
[SessionEndHookInput, HookInvocation],
Awaitable[SessionEndHookOutput | None]
]|
@brettcannon Looks like this runs into quite a few merge conflicts - is this something you will get a chance to resolve? |
Yep! I'll go resolve them right now. |
# Conflicts: # python/copilot/__init__.py # python/copilot/client.py # python/copilot/session.py # python/copilot/types.py # python/test_telemetry.py
|
@SteveSandersonMS all resolved. |
579f975 to
bd9ec8c
Compare
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Remove cfg dict intermediary and use keyword parameters directly, fixing ty type checker errors where cfg.get() returned Any | None and shadowed the typed parameter variables. Co-authored-by: Copilot <[email protected]>
Add back SectionTransformFn type, _extract_transform_callbacks helper, _handle_system_message_transform handler, and systemMessage.transform RPC registration that were part of PR github#816 but lost during rebase. Co-authored-by: Copilot <[email protected]>
The customize mode types (SystemPromptSection, SYSTEM_PROMPT_SECTIONS, SectionOverride, SystemMessageCustomizeConfig) were dropped when types.py was deleted but not re-added to session.py. This also moves SectionTransformFn and SectionOverrideAction before SectionOverride so the definitions flow in dependency order. Co-authored-by: Copilot <[email protected]>
Along the way, simplify
copilot.__init__to only export the high-level API.