Skip to content
This repository was archived by the owner on Feb 2, 2024. It is now read-only.

Commit 33ca0f8

Browse files
committed
add tests for function expend_annotations
1 parent ef7e313 commit 33ca0f8

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

numba_typing/tests/test_type_annotations.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import unittest
22
import type_annotations
3-
from typing import Union, Dict, List
3+
from typing import Union, Dict, List, TypeVar
44

55

66
class TestTypeAnnotations(unittest.TestCase):
77

8-
def test_get_func_annotations_exception(self):
8+
def test_get_func_annotations_exceptions(self):
99

1010
def foo(a: int, b, c: str = "string"):
1111
pass
1212
with self.assertRaises(SyntaxError) as raises:
1313
type_annotations.get_func_annotations(foo)
14-
self.assertIn('Not found annotation for parameter b', str(raises.exception))
14+
self.assertIn('No annotation for parameter b', str(raises.exception))
1515

1616
def test_get_cls_annotations(self):
1717
class TestClass(object):
@@ -46,6 +46,17 @@ def func_three(a: Dict[int, str], b: str = "string", c: int = 1):
4646
with self.subTest(func=f.__name__):
4747
self.assertEqual(type_annotations.get_func_annotations(f), expected)
4848

49+
def test_expend_annotations(self):
50+
51+
S = TypeVar('S', float, str)
52+
info = ({'a': [int], 'b': [int, float], 'c': [S]}, {})
53+
result = type_annotations.expend_annotations(info)
54+
expected = [[{'a': int, 'b': int, 'c': float}, {}],
55+
[{'a': int, 'b': int, 'c': str}, {}],
56+
[{'a': int, 'b': float, 'c': float}, {}],
57+
[{'a': int, 'b': float, 'c': str}, {}]]
58+
self.assertEqual(result, expected)
59+
4960

5061
if __name__ == '__main__':
5162
unittest.main()

numba_typing/type_annotations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from inspect import signature
2-
from typing import get_type_hints, Union
2+
from typing import get_type_hints, Union, TypeVar
33
from itertools import product
44
from copy import deepcopy
55

0 commit comments

Comments
 (0)