Skip to content

Commit

Permalink
Use typing.get_type_hints() in python type tests (#1989)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhammond authored Feb 26, 2024
1 parent 51ab7ed commit c1dd07f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
5 changes: 3 additions & 2 deletions fixtures/futures/tests/bindings/test_futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import unittest
from datetime import datetime
import asyncio
import typing

def now():
return datetime.now()
Expand Down Expand Up @@ -210,8 +211,8 @@ async def test():

def test_function_annotations(self):
async def test():
assert sleep.__annotations__ == {"ms": "int", "return": "bool"}
assert sleep_no_return.__annotations__ == {"ms": "int", "return": None}
self.assertEqual(typing.get_type_hints(sleep) , {"ms": int, "return": bool})
self.assertEqual(typing.get_type_hints(sleep_no_return), {"ms": int, "return": type(None)})
asyncio.run(test())

if __name__ == '__main__':
Expand Down
7 changes: 4 additions & 3 deletions fixtures/simple-fns/tests/bindings/test_simple_fns.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

from uniffi_simple_fns import *
import typing

assert get_string() == "String created by Rust"
assert get_int() == 1289
Expand All @@ -17,7 +18,7 @@
assert not set_contains(a_set, "baz")

assert hash_map_identity({"a": "b"}) == {"a": "b"}
assert hash_map_identity.__annotations__ == {
"h": "'dict[str, str]'",
"return": "'dict[str, str]'",
assert typing.get_type_hints(hash_map_identity) == {
"h": dict[str, str],
"return": dict[str, str],
}

0 comments on commit c1dd07f

Please sign in to comment.