You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PEP 718: Specify binding, parametrisation and overload interactions (#4649)
* hopefully final round of changes
* I think fix the build issues?
Sorry I can't test I can't get make installed
* Fix title too short
* fix some grammar typos and build
* Update peps/pep-0718.rst
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
* final round of changes
* Split long sentence in two for style
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
* Update pep-0718.rst
Adresed @gvanrossum comments
* Update pep-0718.rst
Small change
* fix line wrap
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* more line wrap
---------
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>
Co-authored-by: Pablo <48098178+PabloRuizCuevas@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
For overload resolution a new step will be required previous to any other, where the resolver
287
+
will match only the overloads where the subscription may succeed.
288
+
289
+
.. code-block:: python
290
+
291
+
@overload
292
+
def make[*Ts]() ->float: ...
293
+
@overload
294
+
def make[T]() ->int: ...
295
+
296
+
make[int] # matches first and second overload
297
+
make[int, str] # matches only first
298
+
299
+
300
+
Functions Parameterized by ``TypeVarTuple``\ s
301
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
302
+
Currently, type checkers disallow the use of multiple ``TypeVarTuple``\s in their
303
+
generic parameters; however, it is currently valid to have a function as such:
304
+
305
+
.. code-block:: python
306
+
307
+
def foo[*T, *U](bar: Bar[*T], baz: Baz[*U]): ...
308
+
def spam[*T](bar: Bar[*T]): ...
309
+
310
+
This PEP does not allow functions like ``foo`` to be subscripted, for the same reason
311
+
as defined in :pep:`PEP 646<646#multiple-type-variable-tuples-not-allowed>`, the type
312
+
variables cannot be resolved unambiguously with the current syntax.
313
+
314
+
.. code-block:: python
315
+
316
+
foo[int, str, bool, complex](Bar(), Baz()) # Invalid: cannot determine which parameters are passed to *T and *U. Explicitly parameterise the instances individually
317
+
spam[int, str, bool, complex](Bar()) # OK
318
+
319
+
Binding Rules
320
+
^^^^^^^^^^^^^
321
+
Method subscription (including ``classmethods`` and ``staticmethods``), should only
322
+
allow their function's type parameters and not the enclosing class's.
323
+
Subscription should follow the rules specified in :pep:`PEP 696<696#binding-rules>`;
324
+
methods should bind type parameters on attribute access.
325
+
326
+
.. code-block:: python
327
+
328
+
class C[T]:
329
+
def method[U](self, x: T, y: U): ...
330
+
@classmethod
331
+
defcls[U](cls, x: T, y: U): ...
332
+
333
+
C[int].method[str](0, "") # OK
334
+
C[int].cls[str](0, "") # OK
335
+
C.cls[int, str](0, "") # Invalid: too many type parameters
0 commit comments