@@ -196,8 +196,10 @@ Only the overloads (the ``@overload``-decorated signatures) should be
196
196
considered for matching purposes. The implementation, if provided,
197
197
should be ignored for purposes of overload matching.
198
198
199
+ Step 1
200
+ ~~~~~~
199
201
200
- Step 1: Examine the argument list to determine the number of
202
+ Examine the argument list to determine the number of
201
203
positional and keyword arguments. Use this information to eliminate any
202
204
overload candidates that are not plausible based on their
203
205
input signatures.
@@ -207,8 +209,10 @@ input signatures.
207
209
it as if it were a non-overloaded function call and stop.
208
210
- If two or more candidate overloads remain, proceed to step 2.
209
211
212
+ Step 2
213
+ ~~~~~~
210
214
211
- Step 2: Evaluate each remaining overload as a regular (non-overloaded)
215
+ Evaluate each remaining overload as a regular (non-overloaded)
212
216
call to determine whether it is compatible with the supplied
213
217
argument list. Unlike step 1, this step considers the types of the parameters
214
218
and arguments. During this step, do not generate any user-visible errors.
@@ -219,8 +223,10 @@ Simply record which of the overloads result in evaluation errors.
219
223
Evaluate it as if it were a non-overloaded function call and stop.
220
224
- If two or more candidate overloads remain, proceed to step 4.
221
225
226
+ Step 3
227
+ ~~~~~~
222
228
223
- Step 3: If step 2 produces errors for all overloads, perform
229
+ If step 2 produces errors for all overloads, perform
224
230
"argument type expansion". Union types can be expanded
225
231
into their constituent subtypes. For example, the type ``int | str `` can
226
232
be expanded into ``int `` and ``str ``.
@@ -248,8 +254,10 @@ expanded argument lists.
248
254
For additional details about argument type expansion, see
249
255
`argument-type-expansion `_ below.
250
256
257
+ Step 4
258
+ ~~~~~~
251
259
252
- Step 4: If the argument list is compatible with two or more overloads,
260
+ If the argument list is compatible with two or more overloads,
253
261
determine whether one or more of the overloads has a variadic parameter
254
262
(either ``*args `` or ``**kwargs ``) that maps to a corresponding argument
255
263
that supplies an indeterminate number of positional or keyword arguments.
@@ -260,8 +268,10 @@ If so, eliminate overloads that do not have a variadic parameter.
260
268
call and stop.
261
269
- If two or more candidate overloads remain, proceed to step 5.
262
270
271
+ Step 5
272
+ ~~~~~~
263
273
264
- Step 5: For all arguments, determine whether all possible
274
+ For all arguments, determine whether all possible
265
275
:term: `materializations <materialize> ` of the argument's type are assignable to
266
276
the corresponding parameter type for each of the remaining overloads. If so,
267
277
eliminate all of the subsequent remaining overloads.
@@ -295,10 +305,15 @@ for all remaining overloads are :term:`equivalent`, proceed to step 6.
295
305
If the return types are not equivalent, overload matching is ambiguous. In
296
306
this case, assume a return type of ``Any `` and stop.
297
307
308
+ Step 6
309
+ ~~~~~~
298
310
299
- Step 6: Choose the first remaining candidate overload as the winning
311
+ Choose the first remaining candidate overload as the winning
300
312
match. Evaluate it as if it were a non-overloaded function call and stop.
301
313
314
+ Examples
315
+ ~~~~~~~~
316
+
302
317
Example 1::
303
318
304
319
@overload
0 commit comments