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

  • Escaping the template pattern hellscape in Python
  • Finding flow amid chaos
  • The diminishing half-life of knowledge
  • Oh my poor business logic
  • Pesky little scripts
  • Footnotes for the win
  • Dotfile stewardship for the indolent
  • An ode to the neo-grotesque web
  • Self-hosted Google Fonts in Hugo
  • Configuring options in Go