Skip to content

Commit 1f19dc9

Browse files
author
Andrei Bratu
committed
fix mypy linting
1 parent 7becdeb commit 1f19dc9

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

src/humanloop/decorators/flow.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import asyncio
22
import logging
33
from functools import wraps
4-
from typing import Any, Callable, Optional, TypeVar
4+
from typing import Any, Awaitable, Callable, Coroutine, Optional, TypeVar
55
from typing_extensions import ParamSpec
66

77
from opentelemetry.trace import Span, Tracer
@@ -123,7 +123,7 @@ def wrapper(*args: P.args, **kwargs: P.kwargs) -> Optional[R]:
123123
return func_output # type: ignore [return-value]
124124

125125
@wraps(func)
126-
async def async_wrapper(*args: P.args, **kwargs: P.kwargs) -> Optional[R]:
126+
async def async_wrapper(*args: P.args, **kwargs: P.kwargs) -> Awaitable[Optional[R]]:
127127
span: Span
128128
with set_decorator_context(
129129
DecoratorContext(
@@ -157,7 +157,8 @@ async def async_wrapper(*args: P.args, **kwargs: P.kwargs) -> Optional[R]:
157157
log_error: Optional[str]
158158
log_output_message: Optional[ChatMessage]
159159
try:
160-
func_output = await func(*args, **kwargs)
160+
# Polymorphic decorator does not recognize the function is a coroutine
161+
func_output = await func(*args, **kwargs) # type: ignore [misc]
161162
if (
162163
isinstance(func_output, dict)
163164
and len(func_output.keys()) == 2
@@ -206,7 +207,8 @@ async def async_wrapper(*args: P.args, **kwargs: P.kwargs) -> Optional[R]:
206207
version=FlowDict(**flow_kernel), # type: ignore
207208
callable=async_wrapper,
208209
)
209-
return async_wrapper
210+
# Polymorphic decorator does not recognize the function is a coroutine
211+
return async_wrapper # type: ignore [return-value]
210212

211213
# If the decorated function is a sync function, return the sync wrapper
212214
wrapper.file = File( # type: ignore

src/humanloop/decorators/tool.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from dataclasses import dataclass
99
from functools import wraps
1010
from inspect import Parameter
11-
from typing import Any, Callable, Literal, Mapping, Optional, Sequence, TypeVar, TypedDict, Union
11+
from typing import Any, Awaitable, Callable, Coroutine, Literal, Mapping, Optional, Sequence, TypeVar, TypedDict, Union
1212
from typing_extensions import ParamSpec
1313

1414
from opentelemetry.trace import Tracer
@@ -114,7 +114,7 @@ def wrapper(*args: P.args, **kwargs: P.kwargs) -> Optional[R]:
114114
return func_output
115115

116116
@wraps(func)
117-
async def async_wrapper(*args: P.args, **kwargs: P.kwargs) -> Optional[R]:
117+
async def async_wrapper(*args: P.args, **kwargs: P.kwargs) -> Awaitable[Optional[R]]:
118118
evaluation_context = get_evaluation_context()
119119
if evaluation_context is not None:
120120
if evaluation_context.path == path:
@@ -135,7 +135,8 @@ async def async_wrapper(*args: P.args, **kwargs: P.kwargs) -> Optional[R]:
135135

136136
func_output: Optional[R]
137137
try:
138-
func_output = await func(*args, **kwargs)
138+
# Polymorphic decorator does not recognize the function is a coroutine
139+
func_output = await func(*args, **kwargs) # type: ignore [misc]
139140
log_output = process_output(
140141
func=func,
141142
output=func_output,
@@ -168,7 +169,8 @@ async def async_wrapper(*args: P.args, **kwargs: P.kwargs) -> Optional[R]:
168169
)
169170

170171
# Return the output of the decorated function
171-
return func_output
172+
# Polymorphic decorator does not recognize the function is a coroutine
173+
return func_output # type: ignore [return-value]
172174

173175
# If the decorated function is an async function, return the async wrapper
174176
if asyncio.iscoroutinefunction(func):
@@ -178,7 +180,8 @@ async def async_wrapper(*args: P.args, **kwargs: P.kwargs) -> Optional[R]:
178180
version=tool_kernel,
179181
callable=async_wrapper,
180182
)
181-
return async_wrapper
183+
# Polymorphic decorator does not recognize the function is a coroutine
184+
return async_wrapper # type: ignore [return-value]
182185

183186
# If the decorated function is a sync function, return the sync wrapper
184187
wrapper.file = File( # type: ignore

tests/conftest.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,12 @@ def hl_test_exporter() -> HumanloopSpanExporter:
126126
Test Exporter where HTTP calls to Humanloop API
127127
are mocked.
128128
"""
129-
client = MagicMock()
130-
exporter = HumanloopSpanExporter(client=client)
129+
hl_client_headers = MagicMock()
130+
hl_client_base_url = MagicMock()
131+
exporter = HumanloopSpanExporter(
132+
hl_client_headers=hl_client_headers,
133+
hl_client_base_url=hl_client_base_url,
134+
)
131135
return exporter
132136

133137

0 commit comments

Comments
 (0)