这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@matiasanaya
Copy link
Contributor

@matiasanaya matiasanaya commented Sep 29, 2025

I believe we should add mypy for typechecking. If this is valuable, I'd need to fix / silence the following errors as part of this PR:

❯ a2a-x402 matiasanaya/pkg-typecheck uv run --directory=python/x402_a2a typecheck
type_defs/errors.py:180: error: Argument 1 to "get" of "dict" has incompatible type "type[Exception]"; expected "type[x402Error]"  [arg-type]
core/utils.py:55: error: Unexpected keyword argument "messageId" for "Message"; did you mean "message_id"?  [call-arg]
core/utils.py:59: error: List item 0 has incompatible type "TextPart"; expected "Part"  [list-item]
.venv/lib/python3.11/site-packages/a2a/types.py: note: "Message" defined here
core/utils.py:58: error: Argument "role" to "Message" has incompatible type "str"; expected "Role"  [arg-type]
core/utils.py:187: error: Unexpected keyword argument "messageId" for "Message"; did you mean "message_id"?  [call-arg]
core/utils.py:191: error: List item 0 has incompatible type "TextPart"; expected "Part"  [list-item]
core/utils.py:189: error: Argument "role" to "Message" has incompatible type "str"; expected "Role"  [arg-type]
core/utils.py:221: error: Unexpected keyword argument "messageId" for "Message"; did you mean "message_id"?  [call-arg]
core/utils.py:224: error: List item 0 has incompatible type "TextPart"; expected "Part"  [list-item]
core/utils.py:223: error: Argument "role" to "Message" has incompatible type "str"; expected "Role"  [arg-type]
core/utils.py:249: error: Unexpected keyword argument "messageId" for "Message"; did you mean "message_id"?  [call-arg]
core/utils.py:252: error: List item 0 has incompatible type "TextPart"; expected "Part"  [list-item]
core/utils.py:251: error: Argument "role" to "Message" has incompatible type "str"; expected "Role"  [arg-type]
core/utils.py:286: error: Unexpected keyword argument "messageId" for "Message"; did you mean "message_id"?  [call-arg]
core/utils.py:289: error: List item 0 has incompatible type "TextPart"; expected "Part"  [list-item]
core/utils.py:288: error: Argument "role" to "Message" has incompatible type "str"; expected "Role"  [arg-type]
core/helpers.py:201: error: Incompatible types in assignment (expression has type "str | TokenAmount", variable has type "str")  [assignment]
core/agent.py:63: error: List item 0 has incompatible type "dict[Any, Any]"; expected "AgentExtension"  [list-item]
core/agent.py:84: error: Argument 1 to "AgentCard" has incompatible type "**dict[str, object]"; expected "list[AgentInterface] | None"  [arg-type]
core/agent.py:84: error: Argument 1 to "AgentCard" has incompatible type "**dict[str, object]"; expected "AgentCapabilities"  [arg-type]
core/agent.py:84: error: Argument 1 to "AgentCard" has incompatible type "**dict[str, object]"; expected "list[str]"  [arg-type]
core/agent.py:84: error: Argument 1 to "AgentCard" has incompatible type "**dict[str, object]"; expected "str"  [arg-type]
core/agent.py:84: error: Argument 1 to "AgentCard" has incompatible type "**dict[str, object]"; expected "str | None"  [arg-type]
core/agent.py:84: error: Argument 1 to "AgentCard" has incompatible type "**dict[str, object]"; expected "AgentProvider | None"  [arg-type]
core/agent.py:84: error: Argument 1 to "AgentCard" has incompatible type "**dict[str, object]"; expected "list[dict[str, list[str]]] | None"  [arg-type]
core/agent.py:84: error: Argument 1 to "AgentCard" has incompatible type "**dict[str, object]"; expected "dict[str, SecurityScheme] | None"  [arg-type]
core/agent.py:84: error: Argument 1 to "AgentCard" has incompatible type "**dict[str, object]"; expected "list[AgentCardSignature] | None"  [arg-type]
core/agent.py:84: error: Argument 1 to "AgentCard" has incompatible type "**dict[str, object]"; expected "list[AgentSkill]"  [arg-type]
core/agent.py:84: error: Argument 1 to "AgentCard" has incompatible type "**dict[str, object]"; expected "bool | None"  [arg-type]
executors/server.py:97: error: Argument 2 to "TaskUpdater" has incompatible type "str | None"; expected "str"  [arg-type]
executors/server.py:97: error: Argument 3 to "TaskUpdater" has incompatible type "str | None"; expected "str"  [arg-type]
executors/server.py:102: error: Unexpected keyword argument "contextId" for "Task"; did you mean "context_id"?  [call-arg]
.venv/lib/python3.11/site-packages/a2a/types.py: note: "Task" defined here
executors/server.py:103: error: Argument "id" to "Task" has incompatible type "str | None"; expected "str"  [arg-type]
executors/server.py:110: error: Argument 1 to "get_payment_status_from_task" of "x402Utils" has incompatible type "Task | None"; expected "Task"  [arg-type]
executors/server.py:112: error: Argument 1 to "get_payment_status_from_message" of "x402Utils" has incompatible type "Message | None"; expected "Message"  [arg-type]
executors/server.py:139: error: Argument 1 to "get_payment_payload_from_message" of "x402Utils" has incompatible type "Message | None"; expected "Message"  [arg-type]
executors/server.py:213: error: Item "None" of "Message | None" has no attribute "metadata"  [union-attr]
executors/server.py:215: error: Item "None" of "Message | None" has no attribute "metadata"  [union-attr]
executors/server.py:305: error: Argument 1 to "get_payment_payload_from_message" of "x402Utils" has incompatible type "Message | None"; expected "Message"  [arg-type]
executors/server.py:333: error: Unexpected keyword argument "contextId" for "Task"; did you mean "context_id"?  [call-arg]
core/wallet.py:73: error: "Account" has no attribute "address"  [attr-defined]
core/wallet.py:85: error: Argument "header" to "sign_payment_header" has incompatible type "dict[str, Any]"; expected "PaymentHeader"  [arg-type]
core/wallet.py:93: error: Unexpected keyword argument "from_" for "EIP3009Authorization"; did you mean "from"?  [call-arg]
.venv/lib/python3.11/site-packages/x402/types.py: note: "EIP3009Authorization" defined here
executors/client.py:68: error: Function does not return a value (it only ever returns None)  [func-returns-value]
executors/client.py:97: error: "x402Utils" has no attribute "record_payment_submission"; maybe "record_payment_success"?  [attr-defined]
Found 45 errors in 7 files (checked 13 source files)

As a note, I've had to rename types to type_defs because mypy wouldn't run based on types shadowing the std lib. There is probably a more elegant solution.

@matiasanaya matiasanaya requested a review from a team as a code owner September 29, 2025 01:22
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @matiasanaya, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request integrates mypy for static type checking across the project, aiming to enhance code quality and reduce runtime errors. A significant part of this effort involved restructuring the 'types' module into 'core/types' to address mypy's import resolution, necessitating widespread updates to import paths. The changes also include adding mypy as a development dependency and a dedicated script for running type checks.

Highlights

  • Type Checker Integration: Introduced mypy for static type checking to improve code reliability and catch errors early in the development cycle.
  • Module Restructuring: Refactored the 'types' module into a 'core/types' subdirectory to resolve import conflicts and ensure mypy functions correctly across the project.
  • Dependency and Script Updates: Added mypy and its dependencies to 'uv.lock' and 'pyproject.toml', along with a new 'typecheck' script for easy execution of type checks.
  • Import Path Adjustments: Updated all relevant import statements across the codebase to reflect the new 'core/types' module path, ensuring consistency and correct type resolution.
Ignored Files
  • Ignored by pattern: .github/workflows/** (1)
    • .github/workflows/python-x402-a2a.yml
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@matiasanaya matiasanaya force-pushed the matiasanaya/pkg-typecheck branch from 1a333de to aa8b3f4 Compare September 29, 2025 01:24
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request is a great step towards improving code quality by introducing mypy for static type checking. The main change involves refactoring the project structure by moving the types package into core, and updating all import paths accordingly. The configuration changes in pyproject.toml and lock files to add and configure mypy are also correct.

I've found a minor maintainability issue regarding redundant local imports in core/utils.py. Consolidating these at the top of the file would improve readability. Overall, the changes are well-executed and align with the goal of adding type checking.

# Ensure task has a status message for metadata
if not hasattr(task.status, "message") or not task.status.message:
from ..types import Message
from ..core.types import Message
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The Message type is already imported at the top of this file (line 21), making this local import redundant. The TextPart import on the next line is also redundant as it's imported on line 30.

This pattern of redundant local imports occurs on lines 218-219, 246-247, and 283-284. Consolidating imports at the top of the file improves readability and maintainability.

You can refactor this block to:

        if not hasattr(task.status, "message") or not task.status.message:
            task.status.message = Message(
                messageId=f"{task.id}-status",
                role="agent",
                parts=[
                    TextPart(kind="text", text="Payment is required for this service.")
                ],
                metadata={},
            )

@matiasanaya matiasanaya force-pushed the matiasanaya/pkg-typecheck branch from aa8b3f4 to 07f8462 Compare September 29, 2025 12:12
Copy link
Collaborator

@lingzhong lingzhong left a comment

Choose a reason for hiding this comment

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

Thank you @matiasanaya for proposing this, we're well aware!

Two notes:

  1. We're currently focusing on refining the protocol flow so anticipate volatile code changes in both the protocol and the demo paths. Timing-wise it may be better to start enforcing type checks after upcoming volatility settles.
  2. We certainly to want to try and keep the types naming.

@matiasanaya
Copy link
Contributor Author

  1. We're currently focusing on refining the protocol flow so anticipate volatile code changes in both the protocol and the demo paths.

Looking forward to these.

Timing-wise it may be better to start enforcing type checks after upcoming volatility settles.

Agreed

What's the best way to contribute right now given this? Don't want to unnecessarily add extra burden, though I'm trying to integrate x402 payments over A2A to a production agent and I have several thoughts / concerns.

@lingzhong
Copy link
Collaborator

What's the best way to contribute right now given this? Don't want to unnecessarily add extra burden, though I'm trying to integrate x402 payments over A2A to a production agent and I have several thoughts / concerns.

Appreciate your thoughtfulness! Your feedback around production integration will be invaluable, especially pain points and concerns.

Can you open new issues for these concerns? Ideally a separate issue for each independent concern or idea, so appropriate folks can be pulled into the discussions. Hopefully this will reduce significant PR authoring and review taking up cycles prematurely.

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.

2 participants