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
Copy file name to clipboardExpand all lines: peps/pep-8108.rst
+11-11Lines changed: 11 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,12 +8,12 @@ Created: 16-Nov-2025
8
8
Abstract
9
9
========
10
10
11
-
This PEP proposes the addition of a `coroutinedispatch` class to the `functools` module in Python's standard library. The `coroutinedispatch` class enables method overloading based on argument types, supporting both synchronous and asynchronous methods. This feature simplifies the implementation of polymorphic behavior in Python, making it easier to write clean and maintainable code.
11
+
This PEP proposes the addition of a ``coroutinedispatch`` class to the ``functools`` module in Python's standard library. The ``coroutinedispatch`` class enables method overloading based on argument types, supporting both synchronous and asynchronous methods. This feature simplifies the implementation of polymorphic behavior in Python, making it easier to write clean and maintainable code.
12
12
13
13
Motivation
14
14
==========
15
15
16
-
Python currently lacks built-in support for method overloading based on argument types. While developers can achieve similar functionality using conditional statements or external libraries, these approaches often result in verbose and less readable code. Adding a `coroutinedispatch` class to the standard library would:
16
+
Python currently lacks built-in support for method overloading based on argument types. While developers can achieve similar functionality using conditional statements or external libraries, these approaches often result in verbose and less readable code. Adding a ``coroutinedispatch`` class to the standard library would:
17
17
18
18
- Provide a standardized and Pythonic way to implement method overloading.
19
19
- Enhance code readability and maintainability.
@@ -22,16 +22,16 @@ Python currently lacks built-in support for method overloading based on argument
22
22
Rationale
23
23
=========
24
24
25
-
The `coroutinedispatch` class leverages Python's type hints and introspection capabilities to match method implementations based on argument types. This design aligns with Python's dynamic nature while encouraging the use of type annotations. By integrating this functionality into the `functools` module, we ensure consistency with other utility features for functional programming.
25
+
The ``coroutinedispatch`` class leverages Python's type hints and introspection capabilities to match method implementations based on argument types. This design aligns with Python's dynamic nature while encouraging the use of type annotations. By integrating this functionality into the ``functools`` module, we ensure consistency with other utility features for functional programming.
26
26
27
27
Specification
28
28
=============
29
29
30
-
The `coroutinedispatch` class will be implemented as follows:
30
+
The ``coroutinedispatch`` class will be implemented as follows:
31
31
32
-
- **Registration of Methods**: Developers can register multiple implementations of a method using the `@coroutinedispatch` decorator. The decorator inspects the argument types of the decorated function and stores the implementation accordingly.
33
-
- **Type Matching**: When the method is called, the `coroutinedispatch` class matches the provided arguments against the registered implementations. If no exact match is found, a `TypeError` is raised.
34
-
- **Support for Async Methods**: The `coroutinedispatch` class distinguishes between synchronous and asynchronous contexts, allowing developers to define separate implementations for each.
32
+
- **Registration of Methods**: Developers can register multiple implementations of a method using the ``@coroutinedispatch`` decorator. The decorator inspects the argument types of the decorated function and stores the implementation accordingly.
33
+
- **Type Matching**: When the method is called, the ``coroutinedispatch`` class matches the provided arguments against the registered implementations. If no exact match is found, a ``TypeError`` is raised.
34
+
- **Support for Async Methods**: The ``coroutinedispatch`` class distinguishes between synchronous and asynchronous contexts, allowing developers to define separate implementations for each.
35
35
36
36
Example Usage
37
37
-------------
@@ -73,22 +73,22 @@ Example Usage
73
73
Backwards Compatibility
74
74
=======================
75
75
76
-
This proposal introduces a new class to the `functools` module and does not modify any existing functionality. As such, it is fully backwards compatible.
76
+
This proposal introduces a new class to the ``functools`` module and does not modify any existing functionality. As such, it is fully backwards compatible.
77
77
78
78
Security Implications
79
79
=====================
80
80
81
-
The `coroutinedispatch` class relies on Python's type hints and introspection capabilities. It does not introduce any new security risks beyond those inherent to dynamic type checking.
81
+
The ``coroutinedispatch`` class relies on Python's type hints and introspection capabilities. It does not introduce any new security risks beyond those inherent to dynamic type checking.
82
82
83
83
How to Teach This
84
84
=================
85
85
86
-
The `coroutinedispatch` class should be documented in the Python standard library reference, with examples demonstrating its usage. Tutorials and guides on functional programming in Python can include sections on `coroutinedispatch` to showcase its benefits.
86
+
The ``coroutinedispatch`` class should be documented in the Python standard library reference, with examples demonstrating its usage. Tutorials and guides on functional programming in Python can include sections on ``coroutinedispatch`` to showcase its benefits.
87
87
88
88
Reference Implementation
89
89
=========================
90
90
91
-
A reference implementation of the `coroutinedispatch` class is provided below:
91
+
A reference implementation of the ``coroutinedispatch`` class is provided below:
0 commit comments