Skip to content

Commit 3cb0f71

Browse files
committed
fix: type issues
1 parent ed6d138 commit 3cb0f71

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

tests/client/test_auth_middleware.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import json
22

3-
from collections.abc import Callable, Generator
3+
from collections.abc import Callable
44
from dataclasses import dataclass
55
from typing import Any
66

@@ -101,7 +101,7 @@ async def send_message(
101101

102102

103103
@pytest.fixture
104-
def store() -> Generator[InMemoryContextCredentialStore, Any, None]:
104+
def store():
105105
store = InMemoryContextCredentialStore()
106106
yield store
107107

tests/utils/test_telemetry.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,32 @@
22

33
from typing import NoReturn
44
from unittest import mock
5-
from unittest.mock import MagicMock
65

76
import pytest
87

98
from a2a.utils.telemetry import trace_class, trace_function
109

1110

1211
@pytest.fixture
13-
def mock_span() -> MagicMock:
12+
def mock_span() -> mock.MagicMock:
1413
return mock.MagicMock()
1514

1615

1716
@pytest.fixture
18-
def mock_tracer(mock_span: MagicMock) -> MagicMock:
17+
def mock_tracer(mock_span: mock.MagicMock) -> mock.MagicMock:
1918
tracer = mock.MagicMock()
2019
tracer.start_as_current_span.return_value.__enter__.return_value = mock_span
2120
tracer.start_as_current_span.return_value.__exit__.return_value = False
2221
return tracer
2322

2423

2524
@pytest.fixture(autouse=True)
26-
def patch_trace_get_tracer(mock_tracer: MagicMock):
25+
def patch_trace_get_tracer(mock_tracer: mock.MagicMock):
2726
with mock.patch('opentelemetry.trace.get_tracer', return_value=mock_tracer):
2827
yield
2928

3029

31-
def test_trace_function_sync_success(mock_span: MagicMock):
30+
def test_trace_function_sync_success(mock_span: mock.MagicMock):
3231
@trace_function
3332
def foo(x, y):
3433
return x + y
@@ -40,7 +39,7 @@ def foo(x, y):
4039
mock_span.record_exception.assert_not_called()
4140

4241

43-
def test_trace_function_sync_exception(mock_span: MagicMock):
42+
def test_trace_function_sync_exception(mock_span: mock.MagicMock):
4443
@trace_function
4544
def bar() -> NoReturn:
4645
raise ValueError('fail')
@@ -51,7 +50,9 @@ def bar() -> NoReturn:
5150
mock_span.set_status.assert_any_call(mock.ANY, description='fail')
5251

5352

54-
def test_trace_function_sync_attribute_extractor_called(mock_span: MagicMock):
53+
def test_trace_function_sync_attribute_extractor_called(
54+
mock_span: mock.MagicMock,
55+
):
5556
called = {}
5657

5758
def attr_extractor(span, args, kwargs, result, exception) -> None:
@@ -69,7 +70,7 @@ def foo() -> int:
6970

7071

7172
def test_trace_function_sync_attribute_extractor_error_logged(
72-
mock_span: MagicMock,
73+
mock_span: mock.MagicMock,
7374
):
7475
with mock.patch('a2a.utils.telemetry.logger') as logger:
7576

@@ -88,7 +89,7 @@ def foo() -> int:
8889

8990

9091
@pytest.mark.asyncio
91-
async def test_trace_function_async_success(mock_span: MagicMock):
92+
async def test_trace_function_async_success(mock_span: mock.MagicMock):
9293
@trace_function
9394
async def foo(x):
9495
await asyncio.sleep(0)
@@ -101,7 +102,7 @@ async def foo(x):
101102

102103

103104
@pytest.mark.asyncio
104-
async def test_trace_function_async_exception(mock_span: MagicMock):
105+
async def test_trace_function_async_exception(mock_span: mock.MagicMock):
105106
@trace_function
106107
async def bar() -> NoReturn:
107108
await asyncio.sleep(0)
@@ -115,7 +116,7 @@ async def bar() -> NoReturn:
115116

116117
@pytest.mark.asyncio
117118
async def test_trace_function_async_attribute_extractor_called(
118-
mock_span: MagicMock,
119+
mock_span: mock.MagicMock,
119120
):
120121
called = {}
121122

@@ -132,7 +133,7 @@ async def foo() -> int:
132133
assert called['called']
133134

134135

135-
def test_trace_function_with_args_and_attributes(mock_span: MagicMock):
136+
def test_trace_function_with_args_and_attributes(mock_span: mock.MagicMock):
136137
@trace_function(span_name='custom.span', attributes={'foo': 'bar'})
137138
def foo() -> int:
138139
return 1
@@ -141,7 +142,7 @@ def foo() -> int:
141142
mock_span.set_attribute.assert_any_call('foo', 'bar')
142143

143144

144-
def test_trace_class_exclude_list(mock_span: MagicMock):
145+
def test_trace_class_exclude_list(mock_span: mock.MagicMock):
145146
@trace_class(exclude_list=['skip_me'])
146147
class MyClass:
147148
def a(self) -> str:
@@ -161,7 +162,7 @@ def __str__(self):
161162
assert not hasattr(obj.skip_me, '__wrapped__')
162163

163164

164-
def test_trace_class_include_list(mock_span: MagicMock):
165+
def test_trace_class_include_list(mock_span: mock.MagicMock):
165166
@trace_class(include_list=['only_this'])
166167
class MyClass:
167168
def only_this(self) -> str:
@@ -177,7 +178,7 @@ def not_this(self) -> str:
177178
assert not hasattr(obj.not_this, '__wrapped__')
178179

179180

180-
def test_trace_class_dunder_not_traced(mock_span: MagicMock):
181+
def test_trace_class_dunder_not_traced(mock_span: mock.MagicMock):
181182
@trace_class()
182183
class MyClass:
183184
def __init__(self):

0 commit comments

Comments
 (0)