mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2024-11-23 13:09:49 +00:00
add annotations type test cases
This commit is contained in:
parent
afa6a00db8
commit
c7b20edba0
BIN
test/bytecode_3.7_run/04_def_annotate.pyc
Normal file
BIN
test/bytecode_3.7_run/04_def_annotate.pyc
Normal file
Binary file not shown.
@ -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)
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user