MCPcopy
hub / github.com/hylang/hy / rename_function

Function rename_function

hy/macros.py:422–445  ·  view source on GitHub ↗

Create a copy of a function, but with a new name.

(f, new_name)

Source from the content-addressed store, hash-verified

420
421
422def rename_function(f, new_name):
423 """Create a copy of a function, but with a new name."""
424 f = type(f)(
425 f.__code__.replace(
426 co_name=new_name,
427 **(
428 {
429 "co_qualname": re.sub(
430 r"\.[^.+]\Z", "." + new_name, f.__code__.co_qualname
431 )
432 if "." in f.__code__.co_qualname
433 else new_name
434 }
435 if PY3_11
436 else {}
437 ),
438 ),
439 f.__globals__,
440 str(new_name),
441 f.__defaults__,
442 f.__closure__,
443 )
444 f.__dict__.update(f.__dict__)
445 return f

Callers 2

reader_macroFunction · 0.85
install_macroFunction · 0.85

Calls 1

replaceMethod · 0.45

Tested by

no test coverage detected