Skip to content

Commit ecbc21b

Browse files
committed
handle docstring correctly for the first multimethod, too
1 parent d2785a5 commit ecbc21b

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

unpythonic/dispatch.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -604,16 +604,22 @@ def register(multimethod):
604604

605605
# Update entry point docstring to include docs for the new multimethod,
606606
# and its call signature.
607-
our_doc = _format_method((multimethod, type_signature))
607+
call_signature_desc = _format_method((multimethod, type_signature))
608+
our_doc = call_signature_desc
608609
if multimethod.__doc__:
609610
our_doc += "\n" + multimethod.__doc__
610-
if dispatcher.__doc__:
611+
612+
isfirstmultimethod = len(dispatcher._method_registry) == 1
613+
if isfirstmultimethod or not dispatcher.__doc__:
614+
# Override the original doc of the function that was converted
615+
# into the dispatcher; this adds the call signature to the top.
616+
dispatcher.__doc__ = our_doc
617+
else:
618+
# Add the call signature and doc for the new multimethod.
611619
dispatcher.__doc__ += "\n\n" + ("-" * 80) + "\n"
612620
dispatcher.__doc__ += our_doc
613-
else:
614-
dispatcher.__doc__ = our_doc
615621

616-
return dispatcher # Replace the callable with this generic function's dispatcher.
622+
return dispatcher # Replace the multimethod callable with this generic function's dispatcher.
617623

618624
dispatcher._register = register
619625
_dispatcher_registry[fullname] = dispatcher

0 commit comments

Comments
 (0)