-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy path3.5.py
More file actions
executable file
·58 lines (32 loc) · 1.06 KB
/
3.5.py
File metadata and controls
executable file
·58 lines (32 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python3.5
import asyncio
from passed import passed
# https://docs.python.org/3/whatsnew/3.5.html
from typing import Callable, List, NewType
def function_with_type_annotation(a: str) -> str:
return a
# But the Python runtime does not enforce function.
assert function_with_type_annotation(1.2) == 1.2
Vector_type_alias = List[float]
def scale(scalar: float, vector: Vector_type_alias) -> Vector_type_alias:
return [scalar * num for num in vector]
assert scale(2, [1.1, 3.3]) == [2.2, 6.6]
UserId = NewType('UserId', int)
some_id = UserId(1)
def valid(id: UserId) -> bool:
return True
def feeder(get_next_item: Callable[[], str]) -> None:
pass
def async_query(on_success: Callable[[int], None],
on_error: Callable[[int, Exception], None]) -> None:
pass
# https://docs.python.org/3.5/whatsnew/3.5.html#pep-492-coroutines-with-async-and-await-syntax
async def coroutine():
return 1
loop = asyncio.get_event_loop()
try:
r = loop.run_until_complete(coroutine())
finally:
loop.close()
assert r == 1
passed()