add annotations type test cases

This commit is contained in:
x0ret 2019-06-06 19:14:03 +04:30
parent afa6a00db8
commit c7b20edba0
3 changed files with 29 additions and 5 deletions

Binary file not shown.

View File

@ -18,13 +18,29 @@ def div(a: dict(type=float, help='the dividend'),
"""Divide a by b"""
return a / b
class TestSignatureObject(unittest.TestCase):
class TestSignatureObject():
def test_signature_on_wkwonly(self):
def test(*, a:float, b:str) -> int:
pass
class SupportsInt(_Protocol):
class SupportsInt():
@abstractmethod
def __int__(self) -> int:
pass
def foo2(a, b: 'annotating b', c: int, *args: str) -> float:
assert foo2.__annotations__['b'] == 'annotating b'
assert foo2.__annotations__['c'] == int
assert foo2.__annotations__['args'] == str
assert foo2.__annotations__['return'] == float
def foo3(a, b: int = 5, **kwargs: float) -> float:
assert foo3.__annotations__['b'] == int
assert foo3.__annotations__['kwargs'] == float
assert foo3.__annotations__['return'] == float
assert b == 5
foo2(1, 'test', 5)
foo3(1)

View File

@ -687,9 +687,17 @@ def make_function3(self, node, is_lambda, nested=1, code_node=None):
params.append(build_param(ast, paramnames[i], defparam,
annotate_dict.get(paramnames[i])))
params += paramnames[i+1:]
for param in paramnames[i+1:]:
if param in annotate_dict:
params.append("%s: %s" % (param, annotate_dict[param]))
else:
params.append(param)
else:
params = paramnames
for param in paramnames:
if param in annotate_dict:
params.append("%s: %s" % (param, annotate_dict[param]))
else:
params.append(param)
params.reverse() # back to correct order