Skip to content

Commit

Permalink
Dispatch: Improved docs
Browse files Browse the repository at this point in the history
  • Loading branch information
erezsh committed Aug 23, 2024
1 parent bc761f0 commit 2bcf5d4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
27 changes: 13 additions & 14 deletions docs/dispatch.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,6 @@ Features:
- Fast


Decorator
---------

.. autofunction:: runtype.multidispatch

.. autofunction:: runtype.Dispatch

.. autoclass:: runtype.dispatch.MultiDispatch
:members: choices, feed_token, copy, pretty, resume_parse, exhaust_lexer, accepts, as_immutable

.. autoclass:: runtype.dispatch.DispatchError



What is multiple-dispatch?
--------------------------

Expand Down Expand Up @@ -120,6 +106,19 @@ Then, the group can be used as a decorator for any number of functions, in any m
Functions will still be grouped by name.


Decorator
---------

.. autofunction:: runtype.multidispatch

.. autofunction:: runtype.Dispatch

.. autoclass:: runtype.dispatch.MultiDispatch
:members: choices, feed_token, copy, pretty, resume_parse, exhaust_lexer, accepts, as_immutable

.. autoclass:: runtype.dispatch.DispatchError


Specificity
-----------

Expand Down
12 changes: 6 additions & 6 deletions runtype/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,25 @@ def decorate(self, f: Callable) -> Callable:
>>> from runtype import multidispatch as md
>>> @md
... def add1(i: Optional[int]):
... def add1(i: int):
... return i + 1
>>> @md
... def add1(s: Optional[str]):
... return s + "1"
... def add1(s: str):
... return s + '1'
>>> @md
... def add1(a): # accepts any type (least-specific)
... return (a, 1)
... return ('add', a, 1)
>>> add1(1)
2
>>> add1("1")
>>> add1('1')
11
>>> add1(1.0)
(1.0, 1)
('add', 1.0, 1)
"""
Expand Down
4 changes: 2 additions & 2 deletions runtype/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class MultiDispatch:
"""Creates a dispatch group for multiple dispatch
Parameters:
typesystem - instance for interfacing with the typesystem
typesystem (Typesystem): Which type-system to use for dispatch.
test_subtypes: indices of params that should be matched by subclass instead of isinstance.
(will be soon deprecated, and replaced by using Type[..] annotations)
(will be soon deprecated and replaced by using Type[..] annotations)
"""

def __init__(self, typesystem: TypeSystem, test_subtypes: Sequence[int] = ()):
Expand Down

0 comments on commit 2bcf5d4

Please sign in to comment.