Skip to content

Commit 9e57aa5

Browse files
committed
docs: Fix use_signature formatting issue
Related to vega#3444 (comment) *Placeholder for screenshot(s) documenting the bug*
1 parent 54a68a3 commit 9e57aa5

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

altair/utils/core.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -688,29 +688,32 @@ def infer_vegalite_type_for_dfi_column(
688688
raise ValueError(msg)
689689

690690

691-
def use_signature(Obj: Callable[P, Any]): # -> Callable[..., Callable[P, V]]:
692-
"""Apply call signature and documentation of Obj to the decorated method"""
691+
def use_signature(obj: Callable[P, Any]): # -> Callable[..., Callable[P, V]]:
692+
"""Apply call signature and documentation of `obj` to the decorated method"""
693693

694-
def decorate(f: Callable[..., V]) -> Callable[P, V]:
695-
# call-signature of f is exposed via __wrapped__.
696-
# we want it to mimic Obj.__init__
697-
f.__wrapped__ = Obj.__init__ # type: ignore
698-
f._uses_signature = Obj # type: ignore
694+
def decorate(func: Callable[..., V]) -> Callable[P, V]:
695+
# call-signature of func is exposed via __wrapped__.
696+
# we want it to mimic obj.__init__
699697

700-
# Supplement the docstring of f with information from Obj
701-
if Obj.__doc__:
698+
# error: Accessing "__init__" on an instance is unsound,
699+
# since instance.__init__ could be from an incompatible subclass [misc]
700+
wrapped = (
701+
obj.__init__ if (isinstance(obj, type) and issubclass(obj, object)) else obj # type: ignore [misc]
702+
)
703+
func.__wrapped__ = wrapped # type: ignore[attr-defined]
704+
func._uses_signature = obj # type: ignore[attr-defined]
705+
706+
# Supplement the docstring of func with information from obj
707+
if doc_in := obj.__doc__:
708+
doc_lines = doc_in.splitlines(keepends=True)[1:]
702709
# Patch in a reference to the class this docstring is copied from,
703710
# to generate a hyperlink.
704-
doclines = Obj.__doc__.splitlines()
705-
doclines[0] = f"Refer to :class:`{Obj.__name__}`"
706-
707-
if f.__doc__:
708-
doc = f.__doc__ + "\n".join(doclines[1:])
709-
else:
710-
doc = "\n".join(doclines)
711-
f.__doc__ = doc
712-
713-
return f
711+
line_1 = f"{func.__doc__ or f'Refer to :class:`{obj.__name__}`'}\n"
712+
func.__doc__ = "".join((line_1, *doc_lines))
713+
return func
714+
else:
715+
msg = f"Found no doc for {obj!r}"
716+
raise AttributeError(msg)
714717

715718
return decorate
716719

0 commit comments

Comments
 (0)