The constructor for functools.partial()
detects nesting and automatically flattens itself
to a more efficient form. For example:
from functools import partial
def f(*, a: int, b: int, c: int) -> None:
print(f"Args are {a}-{b}-{c}")
g = partial(partial(partial(f, a=1), b=2), c=3)
# Three function calls are flattened into one; free efficiency.
print(g)
# Bare function can be called as 3 arguments were bound previously.
g()
This returns:
functools.partial(<function f at 0x7f4fd16c11f0>, a=1, b=2, c=3)
Args are 1-2-3
Recent posts
- Explicit method overriding with @typing.override
- Quicker startup with module-level __getattr__
- Docker mount revisited
- Topological sort
- Writing a circuit breaker in Go
- Discovering direnv
- Notes on building event-driven systems
- Bash namerefs for dynamic variable referencing
- Behind the blog
- Shell redirection syntax soup