Skip to content
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

Added type hints existence validation to make error message when miss… #5211

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
import functools
import warnings
import typing
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we use from typing import get_type_hints?

from textwrap import dedent
from typing import Any, Callable, Sequence

Expand Down Expand Up @@ -87,6 +88,12 @@ def __init__(
) -> None:
self._func = func
self._global_imports = global_imports

# Validate type hints exist
hints = typing.get_type_hints(func)
if not hints:
raise TypeError(f"Function '{func.__name__}' has no type hints. All parameters must be annotated.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

The issue you referenced, the function argument has type hint. Can this catch the same error?


signature = get_typed_signature(func)
func_name = name or func.__name__
args_model = args_base_model_from_signature(func_name + "args", signature)
Expand Down