forked from mkdocstrings/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerics.py
More file actions
49 lines (36 loc) · 1.04 KB
/
generics.py
File metadata and controls
49 lines (36 loc) · 1.04 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
"""Some module showing generics.
Type Aliases:
SomeType: Some type alias.
"""
type SomeType[Z] = int | list[Z]
"""Some type alias.
Type parameters:
Z: Some type parameter.
"""
class MagicBag[T: (str, bytes) = str](list[T]):
"""A magic bag of items.
Type parameters:
T: Some type.
"""
def __init__[U: (int, bool)](self, *args: T, flag1: U | None = None, flag2: U | None = None) -> None:
"""Initialize bag.
Type parameters:
U: Some flag type.
Parameters:
flag1: Some flag.
flag2: Some flag.
"""
super().__init__(args)
self.flag1 = flag1
self.flag2 = flag2
def mutate[K](self, item: T, into: K) -> K:
"""Shake the bag to mutate an item into something else (and eject it).
Type parameters:
K: Some other type.
Parameters:
item: The item to mutate.
into: Mutate the item into something like this.
Returns:
The mutated item.
"""
...