1
- from _typeshed import Self
1
+ from _typeshed import ReadableBuffer , Self
2
2
from collections .abc import Callable , Mapping
3
3
from typing import Any , AnyStr , Generic , TypeVar , overload
4
4
from typing_extensions import Literal , final
@@ -7,126 +7,273 @@ _T = TypeVar("_T")
7
7
8
8
@final
9
9
class Pattern (Generic [AnyStr ]):
10
- pattern : AnyStr
11
- flags : int
12
- groups : int
13
- groupindex : Mapping [str , int ]
14
- named_lists : Mapping [str , frozenset [AnyStr ]]
10
+ @property
11
+ def flags (self ) -> int : ...
12
+ @property
13
+ def groupindex (self ) -> Mapping [str , int ]: ...
14
+ @property
15
+ def groups (self ) -> int : ...
16
+ @property
17
+ def pattern (self ) -> AnyStr : ...
18
+ @property
19
+ def named_lists (self ) -> Mapping [str , frozenset [AnyStr ]]: ...
20
+ @overload
15
21
def search (
16
- self ,
17
- string : AnyStr ,
18
- pos : int | None = ...,
19
- endpos : int | None = ...,
22
+ self : Pattern [str ],
23
+ string : str ,
24
+ pos : int = ...,
25
+ endpos : int = ...,
26
+ concurrent : bool | None = ...,
27
+ timeout : float | None = ...,
28
+ ) -> Match [str ] | None : ...
29
+ @overload
30
+ def search (
31
+ self : Pattern [bytes ],
32
+ string : ReadableBuffer ,
33
+ pos : int = ...,
34
+ endpos : int = ...,
20
35
concurrent : bool | None = ...,
21
36
timeout : float | None = ...,
22
- ) -> Match [AnyStr ] | None : ...
37
+ ) -> Match [bytes ] | None : ...
38
+ @overload
23
39
def match (
24
- self ,
25
- string : AnyStr ,
26
- pos : int | None = ...,
27
- endpos : int | None = ...,
40
+ self : Pattern [str ],
41
+ string : str ,
42
+ pos : int = ...,
43
+ endpos : int = ...,
44
+ concurrent : bool | None = ...,
45
+ timeout : float | None = ...,
46
+ ) -> Match [str ] | None : ...
47
+ @overload
48
+ def match (
49
+ self : Pattern [bytes ],
50
+ string : ReadableBuffer ,
51
+ pos : int = ...,
52
+ endpos : int = ...,
28
53
concurrent : bool | None = ...,
29
54
timeout : float | None = ...,
30
- ) -> Match [AnyStr ] | None : ...
55
+ ) -> Match [bytes ] | None : ...
56
+ @overload
31
57
def fullmatch (
32
- self ,
33
- string : AnyStr ,
34
- pos : int | None = ...,
35
- endpos : int | None = ...,
58
+ self : Pattern [str ],
59
+ string : str ,
60
+ pos : int = ...,
61
+ endpos : int = ...,
62
+ concurrent : bool | None = ...,
63
+ timeout : float | None = ...,
64
+ ) -> Match [str ] | None : ...
65
+ @overload
66
+ def fullmatch (
67
+ self : Pattern [bytes ],
68
+ string : ReadableBuffer ,
69
+ pos : int = ...,
70
+ endpos : int = ...,
36
71
concurrent : bool | None = ...,
37
72
timeout : float | None = ...,
38
- ) -> Match [AnyStr ] | None : ...
73
+ ) -> Match [bytes ] | None : ...
74
+ @overload
75
+ def split (
76
+ self : Pattern [str ], string : str , maxsplit : int = ..., concurrent : bool | None = ..., timeout : float | None = ...
77
+ ) -> list [str | Any ]: ...
78
+ @overload
39
79
def split (
40
- self , string : AnyStr , maxsplit : int = ..., concurrent : bool | None = ..., timeout : float | None = ...
41
- ) -> list [AnyStr | Any ]: ...
80
+ self : Pattern [bytes ],
81
+ string : ReadableBuffer ,
82
+ maxsplit : int = ...,
83
+ concurrent : bool | None = ...,
84
+ timeout : float | None = ...,
85
+ ) -> list [bytes | Any ]: ...
86
+ @overload
42
87
def splititer (
43
- self , string : AnyStr , maxsplit : int = ..., concurrent : bool | None = ..., timeout : float | None = ...
44
- ) -> Splitter [AnyStr ]: ...
88
+ self : Pattern [str ], string : str , maxsplit : int = ..., concurrent : bool | None = ..., timeout : float | None = ...
89
+ ) -> Splitter [str ]: ...
90
+ @overload
91
+ def splititer (
92
+ self : Pattern [bytes ],
93
+ string : ReadableBuffer ,
94
+ maxsplit : int = ...,
95
+ concurrent : bool | None = ...,
96
+ timeout : float | None = ...,
97
+ ) -> Splitter [bytes ]: ...
98
+ @overload
45
99
def findall (
46
- self ,
47
- string : AnyStr ,
48
- pos : int | None = ...,
49
- endpos : int | None = ...,
100
+ self : Pattern [ str ] ,
101
+ string : str ,
102
+ pos : int = ...,
103
+ endpos : int = ...,
50
104
overlapped : bool = ...,
51
105
concurrent : bool | None = ...,
52
106
timeout : float | None = ...,
53
107
) -> list [Any ]: ...
108
+ @overload
109
+ def findall (
110
+ self : Pattern [bytes ],
111
+ string : ReadableBuffer ,
112
+ pos : int = ...,
113
+ endpos : int = ...,
114
+ overlapped : bool = ...,
115
+ concurrent : bool | None = ...,
116
+ timeout : float | None = ...,
117
+ ) -> list [Any ]: ...
118
+ @overload
54
119
def finditer (
55
- self ,
56
- string : AnyStr ,
120
+ self : Pattern [str ],
121
+ string : str ,
122
+ pos : int = ...,
123
+ endpos : int = ...,
124
+ overlapped : bool = ...,
125
+ concurrent : bool | None = ...,
126
+ timeout : float | None = ...,
127
+ ) -> Scanner [str ]: ...
128
+ @overload
129
+ def finditer (
130
+ self : Pattern [bytes ],
131
+ string : ReadableBuffer ,
132
+ pos : int = ...,
133
+ endpos : int = ...,
134
+ overlapped : bool = ...,
135
+ concurrent : bool | None = ...,
136
+ timeout : float | None = ...,
137
+ ) -> Scanner [bytes ]: ...
138
+ @overload
139
+ def sub (
140
+ self : Pattern [str ],
141
+ repl : str | Callable [[Match [str ]], str ],
142
+ string : str ,
143
+ count : int = ...,
144
+ flags : int = ...,
57
145
pos : int | None = ...,
58
146
endpos : int | None = ...,
59
- overlapped : bool = ...,
60
147
concurrent : bool | None = ...,
61
148
timeout : float | None = ...,
62
- ) -> Scanner [AnyStr ]: ...
149
+ ) -> str : ...
150
+ @overload
63
151
def sub (
64
- self ,
65
- repl : AnyStr | Callable [[Match [AnyStr ]], AnyStr ],
66
- string : AnyStr ,
152
+ self : Pattern [ bytes ] ,
153
+ repl : ReadableBuffer | Callable [[Match [bytes ]], ReadableBuffer ],
154
+ string : ReadableBuffer ,
67
155
count : int = ...,
68
156
flags : int = ...,
69
157
pos : int | None = ...,
70
158
endpos : int | None = ...,
71
159
concurrent : bool | None = ...,
72
160
timeout : float | None = ...,
73
- ) -> AnyStr : ...
161
+ ) -> bytes : ...
162
+ @overload
74
163
def subf (
75
- self ,
76
- format : AnyStr | Callable [[Match [AnyStr ]], AnyStr ],
77
- string : AnyStr ,
164
+ self : Pattern [str ],
165
+ format : str | Callable [[Match [str ]], str ],
166
+ string : str ,
167
+ count : int = ...,
168
+ flags : int = ...,
169
+ pos : int | None = ...,
170
+ endpos : int | None = ...,
171
+ concurrent : bool | None = ...,
172
+ timeout : float | None = ...,
173
+ ) -> str : ...
174
+ @overload
175
+ def subf (
176
+ self : Pattern [bytes ],
177
+ format : ReadableBuffer | Callable [[Match [bytes ]], ReadableBuffer ],
178
+ string : ReadableBuffer ,
179
+ count : int = ...,
180
+ flags : int = ...,
181
+ pos : int | None = ...,
182
+ endpos : int | None = ...,
183
+ concurrent : bool | None = ...,
184
+ timeout : float | None = ...,
185
+ ) -> bytes : ...
186
+ @overload
187
+ def subn (
188
+ self : Pattern [str ],
189
+ repl : str | Callable [[Match [str ]], str ],
190
+ string : str ,
78
191
count : int = ...,
79
192
flags : int = ...,
80
193
pos : int | None = ...,
81
194
endpos : int | None = ...,
82
195
concurrent : bool | None = ...,
83
196
timeout : float | None = ...,
84
- ) -> AnyStr : ...
197
+ ) -> tuple [str , int ]: ...
198
+ @overload
85
199
def subn (
86
- self ,
87
- repl : AnyStr | Callable [[Match [AnyStr ]], AnyStr ],
88
- string : AnyStr ,
200
+ self : Pattern [bytes ],
201
+ repl : ReadableBuffer | Callable [[Match [bytes ]], ReadableBuffer ],
202
+ string : ReadableBuffer ,
203
+ count : int = ...,
204
+ flags : int = ...,
205
+ pos : int | None = ...,
206
+ endpos : int | None = ...,
207
+ concurrent : bool | None = ...,
208
+ timeout : float | None = ...,
209
+ ) -> tuple [bytes , int ]: ...
210
+ @overload
211
+ def subfn (
212
+ self : Pattern [str ],
213
+ format : str | Callable [[Match [str ]], str ],
214
+ string : str ,
89
215
count : int = ...,
90
216
flags : int = ...,
91
217
pos : int | None = ...,
92
218
endpos : int | None = ...,
93
219
concurrent : bool | None = ...,
94
220
timeout : float | None = ...,
95
- ) -> tuple [AnyStr , int ]: ...
221
+ ) -> tuple [str , int ]: ...
222
+ @overload
96
223
def subfn (
97
- self ,
98
- format : AnyStr | Callable [[Match [AnyStr ]], AnyStr ],
99
- string : AnyStr ,
224
+ self : Pattern [ bytes ] ,
225
+ format : ReadableBuffer | Callable [[Match [bytes ]], ReadableBuffer ],
226
+ string : ReadableBuffer ,
100
227
count : int = ...,
101
228
flags : int = ...,
102
229
pos : int | None = ...,
103
230
endpos : int | None = ...,
104
231
concurrent : bool | None = ...,
105
232
timeout : float | None = ...,
106
- ) -> tuple [AnyStr , int ]: ...
233
+ ) -> tuple [bytes , int ]: ...
234
+ @overload
107
235
def scanner (
108
- self ,
109
- string : AnyStr ,
236
+ self : Pattern [ str ] ,
237
+ string : str ,
110
238
pos : int | None = ...,
111
239
endpos : int | None = ...,
112
240
overlapped : bool = ...,
113
241
concurrent : bool | None = ...,
114
242
timeout : float | None = ...,
115
- ) -> Scanner [AnyStr ]: ...
243
+ ) -> Scanner [str ]: ...
244
+ @overload
245
+ def scanner (
246
+ self : Pattern [bytes ],
247
+ string : bytes ,
248
+ pos : int | None = ...,
249
+ endpos : int | None = ...,
250
+ overlapped : bool = ...,
251
+ concurrent : bool | None = ...,
252
+ timeout : float | None = ...,
253
+ ) -> Scanner [bytes ]: ...
116
254
117
255
@final
118
256
class Match (Generic [AnyStr ]):
119
-
120
- re : Pattern [AnyStr ]
121
- string : AnyStr
122
- pos : int
123
- endpos : int
124
- partial : bool
125
- regs : tuple [tuple [int , int ], ...]
126
- fuzzy_counts : tuple [int , int , int ]
127
- fuzzy_changes : tuple [list [int ], list [int ], list [int ]]
128
- lastgroup : str | None
129
- lastindex : int | None
257
+ @property
258
+ def pos (self ) -> int : ...
259
+ @property
260
+ def endpos (self ) -> int : ...
261
+ @property
262
+ def lastindex (self ) -> int | None : ...
263
+ @property
264
+ def lastgroup (self ) -> str | None : ...
265
+ @property
266
+ def string (self ) -> AnyStr : ...
267
+ @property
268
+ def re (self ) -> Pattern [AnyStr ]: ...
269
+ @property
270
+ def partial (self ) -> bool : ...
271
+ @property
272
+ def regs (self ) -> tuple [tuple [int , int ], ...]: ...
273
+ @property
274
+ def fuzzy_counts (self ) -> tuple [int , int , int ]: ...
275
+ @property
276
+ def fuzzy_changes (self ) -> tuple [list [int ], list [int ], list [int ]]: ...
130
277
@overload
131
278
def group (self , __group : Literal [0 ] = ...) -> AnyStr : ...
132
279
@overload
@@ -180,16 +327,16 @@ class Match(Generic[AnyStr]):
180
327
181
328
@final
182
329
class Splitter (Generic [AnyStr ]):
183
-
184
- pattern : Pattern [AnyStr ]
330
+ @ property
331
+ def pattern ( self ) -> Pattern [AnyStr ]: ...
185
332
def __iter__ (self : Self ) -> Self : ...
186
333
def __next__ (self ) -> AnyStr | Any : ...
187
334
def split (self ) -> AnyStr | Any : ...
188
335
189
336
@final
190
337
class Scanner (Generic [AnyStr ]):
191
-
192
- pattern : Pattern [AnyStr ]
338
+ @ property
339
+ def pattern ( self ) -> Pattern [AnyStr ]: ...
193
340
def __iter__ (self : Self ) -> Self : ...
194
341
def __next__ (self ) -> Match [AnyStr ]: ...
195
342
def match (self ) -> Match [AnyStr ] | None : ...
0 commit comments