Skip to content

fix(types): resolve type errors and improve type annotations Part 1 #2808

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

hendrixmar
Copy link

This is the first part of fixing all the MyPy errors for the genkit projects. It will split the changes on several PR

@@ -29,7 +29,7 @@
from __future__ import annotations

from collections.abc import Awaitable, Callable
from typing import Union, Type
from typing import Union
Copy link
Contributor

@yesudeep yesudeep Apr 23, 2025

Choose a reason for hiding this comment

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

Please replace the use of Union with |

@@ -18,9 +18,10 @@

import asyncio
from collections.abc import Callable
from typing import Any, Awaitable
Copy link
Contributor

Choose a reason for hiding this comment

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

Please import Awaitable from collections.abc instead: https://docs.python.org/3/library/collections.abc.html#collections.abc.Awaitable

@@ -17,6 +17,7 @@
"""Action utility module for defining and managing action utilities."""

import inspect
import typing
Copy link
Contributor

Choose a reason for hiding this comment

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

is this import required?

@@ -13,6 +13,7 @@
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
from typing import Any
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: blank line before import

please run bin/fmt

@@ -181,6 +182,6 @@ def test_extract_json(name, input_data, expected_data):
test_cases_parse_partial_json,
ids=[tc[0] for tc in test_cases_parse_partial_json],
)
def test_parse_partial_json(name, input_str, expected_data):
def test_parse_partial_json(name: str, input_str: str, expected_data: dict[str, Any]) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: docstrings for test methods to reduce linter noise and explain what the test does

@@ -208,7 +210,7 @@ def visit_ClassDef(self, node: ast.ClassDef) -> ast.ClassDef: # noqa: N802
# For other classes, just copy the rest of the body
new_body.extend(node.body[body_start_index:])

node.body = new_body
node.body = cast( list[ast.stmt], new_body)
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the warning that you see here?

Copy link
Author

Choose a reason for hiding this comment

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

That the node was recognized as a AsT instead of a stmt. Even though the stmt inherit from AsT.

Copy link
Contributor

@yesudeep yesudeep Apr 24, 2025

Choose a reason for hiding this comment

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

casts usually are a sign of underlying issues and are us telling the compiler that "we know better." can you please leave this change out of this pr? the rest looks okay

(for future PRs: every cast should be accompanied by your reasoning)

@@ -83,7 +85,7 @@
test_cases_extract_items,
ids=[tc[0] for tc in test_cases_extract_items],
)
def test_extract_items(name, steps):
def test_extract_items(name: str, steps: list[dict[str, Any]]) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: missed docstring here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants