Skip to content

Commit a7a395e

Browse files
committed
multidispatch base implementation always matches.
Consistent with `singledispatch`. Refs #109.
1 parent a8e9fdd commit a7a395e

File tree

3 files changed

+4
-9
lines changed

3 files changed

+4
-9
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
66
## Unreleased
77
### Changed
88
* `multidispatch` supports variable keyword arguments
9+
* `multidispatch` base implementation always matches
910

1011
## [1.11.2](https://pypi.org/project/multimethod/1.11.2/) - 2024-02-27
1112
### Fixed

multimethod/__init__.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -406,12 +406,7 @@ def __init__(self, func: Callable[..., RETURN]) -> None:
406406
self.pending = set()
407407
self.generics = []
408408
self.signatures = {}
409-
msg = "base implementation will eventually ignore annotations as `singledispatch` does"
410-
with contextlib.suppress(NameError, AttributeError, TypeError):
411-
hints = signature.from_hints(func)
412-
if hints and all(map(issubclass, hints, hints)):
413-
warnings.warn(msg, DeprecationWarning)
414-
super().__init__(func)
409+
self[()] = func
415410

416411
def __get__(self, instance, owner) -> Callable[..., RETURN]:
417412
return self if instance is None else types.MethodType(self, instance) # type: ignore

tests/test_dispatch.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ def func(a: int, b: float = 0.0):
9999
assert method(0, 1.0) == method(0, b=1.0) == 1.0
100100
with pytest.raises(DispatchError, match="0 methods"):
101101
method(0, 0)
102-
with pytest.raises(DispatchError, match="0 methods"), pytest.warns(DeprecationWarning):
103-
multidispatch(func)(0, b=1)
102+
assert multidispatch(func)(0, b=1)
103+
assert multimethod(bool)(1)
104104

105105

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

119119
assert func(0) is func(arg=0) is int
120120
assert func(0, 0.0) is func(arg=0, extra=0.0) is float
121-
assert multidispatch(bool)(1)
122121

123122

124123
def test_concurrency():

0 commit comments

Comments
 (0)