Skip to content

Commit 8082764

Browse files
committed
fix(typing): add missing annotations and typing.cast to event.py and platform tests
1 parent 118bc91 commit 8082764

3 files changed

Lines changed: 11 additions & 9 deletions

File tree

src/google/adk/events/event.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
from __future__ import annotations
1616

1717
from typing import Optional
18+
from typing import Any
19+
from typing import cast
1820

1921
from google.adk.platform import time as platform_time
2022
from google.adk.platform import uuid as platform_uuid
@@ -73,7 +75,7 @@ class Event(LlmResponse):
7375
timestamp: float = Field(default_factory=lambda: platform_time.get_time())
7476
"""The timestamp of the event."""
7577

76-
def model_post_init(self, __context):
78+
def model_post_init(self, __context: Any) -> None:
7779
"""Post initialization logic for the event."""
7880
# Generates a random ID for the event.
7981
if not self.id:
@@ -124,5 +126,5 @@ def has_trailing_code_execution_result(
124126
return False
125127

126128
@staticmethod
127-
def new_id():
128-
return platform_uuid.new_uuid()
129+
def new_id() -> str:
130+
return cast(str, platform_uuid.new_uuid())

tests/unittests/platform/test_time.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@
2222

2323
class TestTime(unittest.TestCase):
2424

25-
def tearDown(self):
25+
def tearDown(self) -> None:
2626
# Reset provider to default after each test
2727
platform_time.reset_time_provider()
2828

29-
def test_default_time_provider(self):
29+
def test_default_time_provider(self) -> None:
3030
# Verify it returns a float that is close to now
3131
now = time.time()
3232
rt_time = platform_time.get_time()
3333
self.assertIsInstance(rt_time, float)
3434
self.assertAlmostEqual(rt_time, now, delta=1.0)
3535

36-
def test_custom_time_provider(self):
36+
def test_custom_time_provider(self) -> None:
3737
# Test override
3838
mock_time = 123456789.0
3939
platform_time.set_time_provider(lambda: mock_time)

tests/unittests/platform/test_uuid.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@
2222

2323
class TestUUID(unittest.TestCase):
2424

25-
def tearDown(self):
25+
def tearDown(self) -> None:
2626
# Reset provider to default after each test
2727
platform_uuid.reset_id_provider()
2828

29-
def test_default_id_provider(self):
29+
def test_default_id_provider(self) -> None:
3030
# Verify it returns a string uuid
3131
uid = platform_uuid.new_uuid()
3232
self.assertIsInstance(uid, str)
3333
# Should be parseable as uuid
3434
uuid.UUID(uid)
3535

36-
def test_custom_id_provider(self):
36+
def test_custom_id_provider(self) -> None:
3737
# Test override
3838
mock_id = "test-id-123"
3939
platform_uuid.set_id_provider(lambda: mock_id)

0 commit comments

Comments
 (0)