-
Notifications
You must be signed in to change notification settings - Fork 235
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
base: main
Are you sure you want to change the base?
Conversation
@@ -29,7 +29,7 @@ | |||
from __future__ import annotations | |||
|
|||
from collections.abc import Awaitable, Callable | |||
from typing import Union, Type | |||
from typing import Union |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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
py/bin/sanitize_schema_typing.py
Outdated
@@ -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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: missed docstring here
This is the first part of fixing all the MyPy errors for the genkit projects. It will split the changes on several PR