-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathexample.py
More file actions
56 lines (42 loc) · 1.58 KB
/
example.py
File metadata and controls
56 lines (42 loc) · 1.58 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
import asyncio
def showcase(a, b, /, c, d, *, e, f):
"""Some code to showcase the syntax.
Docstrings are recognized and have an additional scope.
Color schemas can render them differently from other strings.
HACK doctests are highlighted too.
>>> print('''hello
... world''')
"""
@decorator(param='spam')
async def coroutine(db:aio_db.DatabaseConnection) -> List[str]:
r"""A coroutine."""
await logger.log('working\x12with %r', aio_db)
async with db.transaction():
result = await db.query(...)
print(f'Result: {result!r} {a=} {b=!r}')
print(Rf'data: {c=}')
print(rf'data: {c=}')
mapping = None # type: Dict[int, Any] # PEP 484
# a regular expression
get_regex = lambda: re.compile( # type: ignore
r"""\A
word
(?: # a comment
(?P<fill>.)?
(?P<align>[<>=^]) (?# another comment)
)?
another word\.\.\.
(?:\.(?P<precision>0|(?!0)\d+))?
\Z""",
re.VERBOSE | re.DOTALL)
# NOTE Numbers with leading zeros are invalid in Python 3,
# use 0o...
answer = func(0xdeadbeef + 0b00100001 + 0123 + 0o123 +
1_005_123 + # PEP 515
# complex numbers
.10e12 + 2j) @ mat
# walrus operator
filtered_data = [y for x in data if (y := f(x)) is not None]
# position-only params
bar = lambda q, w, /, e, r: (q + w + e + r)
return R'''No escapes '\' in this \one'''