|
4 | 4 | import typing |
5 | 5 | from typing import Union |
6 | 6 |
|
| 7 | +# fmt: off |
7 | 8 | Mode = typing.Literal[ |
8 | 9 | # Text modes |
9 | | - 'r', |
10 | | - 'rt', |
11 | | - 'tr', # Read text |
12 | | - 'w', |
13 | | - 'wt', |
14 | | - 'tw', # Write text |
15 | | - 'a', |
16 | | - 'at', |
17 | | - 'ta', # Append text |
18 | | - 'x', |
19 | | - 'xt', |
20 | | - 'tx', # Exclusive creation text |
21 | | - 'r+', |
22 | | - '+r', |
23 | | - 'rt+', |
24 | | - 'r+t', |
25 | | - '+rt', |
26 | | - 'tr+', |
27 | | - 't+r', |
28 | | - '+tr', # Read and write text |
29 | | - 'w+', |
30 | | - '+w', |
31 | | - 'wt+', |
32 | | - 'w+t', |
33 | | - '+wt', |
34 | | - 'tw+', |
35 | | - 't+w', |
36 | | - '+tw', # Write and read text |
37 | | - 'a+', |
38 | | - '+a', |
39 | | - 'at+', |
40 | | - 'a+t', |
41 | | - '+at', |
42 | | - 'ta+', |
43 | | - 't+a', |
44 | | - '+ta', # Append and read text |
45 | | - 'x+', |
46 | | - '+x', |
47 | | - 'xt+', |
48 | | - 'x+t', |
49 | | - '+xt', |
50 | | - 'tx+', |
51 | | - 't+x', |
52 | | - '+tx', # Exclusive creation and read text |
53 | | - 'U', |
54 | | - 'rU', |
55 | | - 'Ur', |
56 | | - 'rtU', |
57 | | - 'rUt', |
58 | | - 'Urt', |
59 | | - 'trU', |
60 | | - 'tUr', |
61 | | - 'Utr', # Universal newline support |
| 10 | + # Read text |
| 11 | + 'r', 'rt', 'tr', |
| 12 | + # Write text |
| 13 | + 'w', 'wt', 'tw', |
| 14 | + # Append text |
| 15 | + 'a', 'at', 'ta', |
| 16 | + # Exclusive creation text |
| 17 | + 'x', 'xt', 'tx', |
| 18 | + # Read and write text |
| 19 | + 'r+', '+r', 'rt+', 'r+t', '+rt', 'tr+', 't+r', '+tr', |
| 20 | + # Write and read text |
| 21 | + 'w+', '+w', 'wt+', 'w+t', '+wt', 'tw+', 't+w', '+tw', |
| 22 | + # Append and read text |
| 23 | + 'a+', '+a', 'at+', 'a+t', '+at', 'ta+', 't+a', '+ta', |
| 24 | + # Exclusive creation and read text |
| 25 | + 'x+', '+x', 'xt+', 'x+t', '+xt', 'tx+', 't+x', '+tx', |
| 26 | + # Universal newline support |
| 27 | + 'U', 'rU', 'Ur', 'rtU', 'rUt', 'Urt', 'trU', 'tUr', 'Utr', |
| 28 | + |
62 | 29 | # Binary modes |
63 | | - 'rb', |
64 | | - 'br', # Read binary |
65 | | - 'wb', |
66 | | - 'bw', # Write binary |
67 | | - 'ab', |
68 | | - 'ba', # Append binary |
69 | | - 'xb', |
70 | | - 'bx', # Exclusive creation binary |
71 | | - 'rb+', |
72 | | - 'r+b', |
73 | | - '+rb', |
74 | | - 'br+', |
75 | | - 'b+r', |
76 | | - '+br', # Read and write binary |
77 | | - 'wb+', |
78 | | - 'w+b', |
79 | | - '+wb', |
80 | | - 'bw+', |
81 | | - 'b+w', |
82 | | - '+bw', # Write and read binary |
83 | | - 'ab+', |
84 | | - 'a+b', |
85 | | - '+ab', |
86 | | - 'ba+', |
87 | | - 'b+a', |
88 | | - '+ba', # Append and read binary |
89 | | - 'xb+', |
90 | | - 'x+b', |
91 | | - '+xb', |
92 | | - 'bx+', |
93 | | - 'b+x', |
94 | | - '+bx', # Exclusive creation and read binary |
95 | | - 'rbU', |
96 | | - 'rUb', |
97 | | - 'Urb', |
98 | | - 'brU', |
99 | | - 'bUr', |
100 | | - 'Ubr', |
| 30 | + # Read binary |
| 31 | + 'rb', 'br', |
| 32 | + # Write binary |
| 33 | + 'wb', 'bw', |
| 34 | + # Append binary |
| 35 | + 'ab', 'ba', |
| 36 | + # Exclusive creation binary |
| 37 | + 'xb', 'bx', |
| 38 | + # Read and write binary |
| 39 | + 'rb+', 'r+b', '+rb', 'br+', 'b+r', '+br', |
| 40 | + # Write and read binary |
| 41 | + 'wb+', 'w+b', '+wb', 'bw+', 'b+w', '+bw', |
| 42 | + # Append and read binary |
| 43 | + 'ab+', 'a+b', '+ab', 'ba+', 'b+a', '+ba', |
| 44 | + # Exclusive creation and read binary |
| 45 | + 'xb+', 'x+b', '+xb', 'bx+', 'b+x', '+bx', |
101 | 46 | # Universal newline support in binary mode |
| 47 | + 'rbU', 'rUb', 'Urb', 'brU', 'bUr', 'Ubr', |
102 | 48 | ] |
103 | 49 | Filename = Union[str, pathlib.Path] |
104 | | -IO: typing.TypeAlias = Union[typing.IO[str], typing.IO[bytes]] |
| 50 | +IO: typing.TypeAlias = Union[typing.IO[str], typing.IO[bytes]] # type: ignore[name-defined] |
105 | 51 |
|
106 | 52 |
|
107 | 53 | class FileOpenKwargs(typing.TypedDict): |
|
0 commit comments