Skip to content

Commit b1578d5

Browse files
committed
Simplify vendored unwrap function
1 parent 4210688 commit b1578d5

File tree

1 file changed

+2
-12
lines changed

1 file changed

+2
-12
lines changed

Lib/dataclasses.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -431,31 +431,21 @@ def _tuple_str(obj_name, fields):
431431
# Note the trailing comma, needed if this turns out to be a 1-tuple.
432432
return f'({",".join([f"{obj_name}.{f.name}" for f in fields])},)'
433433

434-
# NOTE: This is a vendored copy of `inspect.unwrap` to speed up import time
435-
def _unwrap(func, *, stop=None):
434+
# NOTE: This is a (simplified) vendored copy of `inspect.unwrap` to speed up import time
435+
def _unwrap(func):
436436
"""Get the object wrapped by *func*.
437437

438438
Follows the chain of :attr:`__wrapped__` attributes returning the last
439439
object in the chain.
440440

441-
*stop* is an optional callback accepting an object in the wrapper chain
442-
as its sole argument that allows the unwrapping to be terminated early if
443-
the callback returns a true value. If the callback never returns a true
444-
value, the last object in the chain is returned as usual. For example,
445-
:func:`signature` uses this to stop unwrapping if any object in the
446-
chain has a ``__signature__`` attribute defined.
447-
448441
:exc:`ValueError` is raised if a cycle is encountered.
449-
450442
"""
451443
f = func # remember the original func for error reporting
452444
# Memoise by id to tolerate non-hashable objects, but store objects to
453445
# ensure they aren't destroyed, which would allow their IDs to be reused.
454446
memo = {id(f): f}
455447
recursion_limit = sys.getrecursionlimit()
456448
while not isinstance(func, type) and hasattr(func, '__wrapped__'):
457-
if stop is not None and stop(func):
458-
break
459449
func = func.__wrapped__
460450
id_func = id(func)
461451
if (id_func in memo) or (len(memo) >= recursion_limit):

0 commit comments

Comments
 (0)