Skip to content

Commit 029476f

Browse files
committed
docs, signatures etc.
1 parent 70f5cb9 commit 029476f

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/pint_array/__init__.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
"""
77

88
import collections
9+
import contextlib
910
import importlib
11+
import inspect
1012
import sys
1113
import textwrap
1214
import types
@@ -673,4 +675,30 @@ def prod(x, /, *args, axis=None, **kwargs):
673675

674676
mod.prod = prod
675677

678+
preface = [
679+
"The following is the documentation for the corresponding "
680+
f"attribute of `{xp.__name__}`.",
681+
"The behavior on pint-wrapped arrays is the same for dimensionless "
682+
"quantities, and may differ for quantities with units.\n\n",
683+
]
684+
preface = "\n".join(preface)
685+
for attribute in mod.__dict__:
686+
# Add documentation if it is not already present
687+
if getattr(mod, attribute).__doc__:
688+
continue
689+
690+
xp_attr = getattr(xp, attribute, None)
691+
mod_attr = getattr(mod, attribute, None)
692+
if xp_attr is not None and mod_attr is not None:
693+
if hasattr(xp_attr, "__doc__"):
694+
with contextlib.suppress(AttributeError, TypeError):
695+
xp_doc = xp_attr.__doc__
696+
getattr(mod, attribute).__doc__ = preface + xp_doc
697+
698+
with contextlib.suppress(ValueError, TypeError):
699+
mod_attr.__signature__ = inspect.signature(xp_attr)
700+
701+
with contextlib.suppress(AttributeError, TypeError):
702+
mod_attr.__name__ = xp_attr.__name__
703+
676704
return mod

0 commit comments

Comments
 (0)