Skip to content

Commit

Permalink
multidispatch base implementation always matches.
Browse files Browse the repository at this point in the history
Consistent with `singledispatch`. Refs #109.
  • Loading branch information
coady committed May 4, 2024
1 parent a8e9fdd commit a7a395e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
## Unreleased
### Changed
* `multidispatch` supports variable keyword arguments
* `multidispatch` base implementation always matches

## [1.11.2](https://pypi.org/project/multimethod/1.11.2/) - 2024-02-27
### Fixed
Expand Down
7 changes: 1 addition & 6 deletions multimethod/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,12 +406,7 @@ def __init__(self, func: Callable[..., RETURN]) -> None:
self.pending = set()
self.generics = []
self.signatures = {}
msg = "base implementation will eventually ignore annotations as `singledispatch` does"
with contextlib.suppress(NameError, AttributeError, TypeError):
hints = signature.from_hints(func)
if hints and all(map(issubclass, hints, hints)):
warnings.warn(msg, DeprecationWarning)
super().__init__(func)
self[()] = func

def __get__(self, instance, owner) -> Callable[..., RETURN]:
return self if instance is None else types.MethodType(self, instance) # type: ignore
Expand Down
5 changes: 2 additions & 3 deletions tests/test_dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ def func(a: int, b: float = 0.0):
assert method(0, 1.0) == method(0, b=1.0) == 1.0
with pytest.raises(DispatchError, match="0 methods"):
method(0, 0)
with pytest.raises(DispatchError, match="0 methods"), pytest.warns(DeprecationWarning):
multidispatch(func)(0, b=1)
assert multidispatch(func)(0, b=1)
assert multimethod(bool)(1)


def test_keywords():
Expand All @@ -118,7 +118,6 @@ def _(arg: int, extra: float):

assert func(0) is func(arg=0) is int
assert func(0, 0.0) is func(arg=0, extra=0.0) is float
assert multidispatch(bool)(1)


def test_concurrency():
Expand Down

0 comments on commit a7a395e

Please sign in to comment.