Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9228c3a

Browse files
authored
Add link anchors for each step of the overload call evaluation algorithm (#2077)
1 parent 3be5b1c commit 9228c3a

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

docs/spec/overload.rst

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,10 @@ Only the overloads (the ``@overload``-decorated signatures) should be
196196
considered for matching purposes. The implementation, if provided,
197197
should be ignored for purposes of overload matching.
198198

199+
Step 1
200+
~~~~~~
199201

200-
Step 1: Examine the argument list to determine the number of
202+
Examine the argument list to determine the number of
201203
positional and keyword arguments. Use this information to eliminate any
202204
overload candidates that are not plausible based on their
203205
input signatures.
@@ -207,8 +209,10 @@ input signatures.
207209
it as if it were a non-overloaded function call and stop.
208210
- If two or more candidate overloads remain, proceed to step 2.
209211

212+
Step 2
213+
~~~~~~
210214

211-
Step 2: Evaluate each remaining overload as a regular (non-overloaded)
215+
Evaluate each remaining overload as a regular (non-overloaded)
212216
call to determine whether it is compatible with the supplied
213217
argument list. Unlike step 1, this step considers the types of the parameters
214218
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.
219223
Evaluate it as if it were a non-overloaded function call and stop.
220224
- If two or more candidate overloads remain, proceed to step 4.
221225

226+
Step 3
227+
~~~~~~
222228

223-
Step 3: If step 2 produces errors for all overloads, perform
229+
If step 2 produces errors for all overloads, perform
224230
"argument type expansion". Union types can be expanded
225231
into their constituent subtypes. For example, the type ``int | str`` can
226232
be expanded into ``int`` and ``str``.
@@ -248,8 +254,10 @@ expanded argument lists.
248254
For additional details about argument type expansion, see
249255
`argument-type-expansion`_ below.
250256

257+
Step 4
258+
~~~~~~
251259

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,
253261
determine whether one or more of the overloads has a variadic parameter
254262
(either ``*args`` or ``**kwargs``) that maps to a corresponding argument
255263
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.
260268
call and stop.
261269
- If two or more candidate overloads remain, proceed to step 5.
262270

271+
Step 5
272+
~~~~~~
263273

264-
Step 5: For all arguments, determine whether all possible
274+
For all arguments, determine whether all possible
265275
:term:`materializations <materialize>` of the argument's type are assignable to
266276
the corresponding parameter type for each of the remaining overloads. If so,
267277
eliminate all of the subsequent remaining overloads.
@@ -295,10 +305,15 @@ for all remaining overloads are :term:`equivalent`, proceed to step 6.
295305
If the return types are not equivalent, overload matching is ambiguous. In
296306
this case, assume a return type of ``Any`` and stop.
297307

308+
Step 6
309+
~~~~~~
298310

299-
Step 6: Choose the first remaining candidate overload as the winning
311+
Choose the first remaining candidate overload as the winning
300312
match. Evaluate it as if it were a non-overloaded function call and stop.
301313

314+
Examples
315+
~~~~~~~~
316+
302317
Example 1::
303318

304319
@overload

0 commit comments

Comments
 (0)