Skip to content

Commit 089a263

Browse files
committed
improve docstrings/comments
1 parent ee71d41 commit 089a263

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

unpythonic/fun.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ def memoized(*args, **kwargs):
8686
# because there are other places in the stdlib, particularly `inspect._signature_get_partial`
8787
# (as of Python 3.8), that expect the standard semantics.
8888
def partial(func, *args, **kwargs):
89-
"""Wrapper over `functools.partial` that type-checks the arguments against the type annotations on `func`.
89+
"""Type-checking `functools.partial`.
90+
91+
This is a wrapper that type-checks the arguments against the type annotations
92+
on `func`, and if the type check passes, calls `functools.partial`.
9093
9194
Arguments can be passed by position or by name; we compute their bindings
9295
to function parameters like Python itself does.
@@ -97,18 +100,18 @@ def partial(func, *args, **kwargs):
97100
Trying to pass an argument of a type that does not match the corresponding
98101
parameter's type specification raises `TypeError` immediately.
99102
100-
Any parameter that does not have a type annotation will not be type-checked.
103+
Any parameter that does not have a type annotation will be ignored in the type check.
101104
102105
Note the check still occurs at run time, but at the use site of `partial`,
103-
when the partially applied function is constructed. This makes it fail-faster
106+
when the partially applied function is constructed. This makes it fail-fast-er
104107
than an `isinstance` check inside the function.
105108
106109
To conveniently make regular calls of the function type-check arguments, too,
107110
see the decorator `unpythonic.dispatch.typed`.
108111
"""
109112
# HACK: As of Python 3.8, `typing.get_type_hints` does not know about `functools.partial` objects,
110113
# HACK: but those objects have `args` and `keywords` attributes, so we can extract what we need.
111-
# TODO: Remove this hack if `typing.get_type_hints` gets support for `functools.partial` at some point.
114+
# TODO: Maybe remove this hack if `typing.get_type_hints` gets support for `functools.partial` at some point.
112115
if isinstance(func, functools_partial):
113116
thecallable = func.func
114117
collected_args = func.args + args

0 commit comments

Comments
 (0)