Skip to content

Commit f04a438

Browse files
committed
format_methods: handle also case of empty multimethod list
1 parent 8d73c7a commit f04a438

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

unpythonic/dispatch.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,13 @@ def format_methods(f):
284284
This calls `list_methods`, which see.
285285
"""
286286
function, _ = getfunc(f)
287-
methods_str = [f" {_format_method(x)}" for x in list_methods(f)]
288-
methods = "\n".join(methods_str)
289-
return f"Multimethods for @{isgeneric(f)} {repr(function.__qualname__)}:\n{methods}"
287+
multimethods = list_methods(f)
288+
if multimethods:
289+
methods_list = [f" {_format_method(x)}" for x in multimethods]
290+
methods_str = "\n".join(methods_list)
291+
else: # pragma: no cover, in practice should always have one method.
292+
methods_str = " <no multimethods registered>"
293+
return f"Multimethods for @{isgeneric(f)} {repr(function.__qualname__)}:\n{methods_str}"
290294

291295
def list_methods(f):
292296
"""Return a list of the multimethods currently registered to `f`.

0 commit comments

Comments
 (0)