Function object (source code)

= Function object

A <function object> is a callable runtime object representing a <function> together with the context needed to execute it. In <CPython>, a Python-defined <function object> refers to a <code object>, its defining global namespace, default argument values and any captured bindings. The <code object> alone does not contain all this context.<Python 3.14 Data Model>[§3.2.8.1, User-defined functions and special attributes; §3.2.13.1, Code objects]{ref}

For example, a factory `make_adder(k)` can return a nested <function> computing `x+k`. Calling the factory with two and five can produce <function objects> sharing one <code object> but retaining different values of `k` through their <programming closures>. Their results on input ten are twelve and fifteen. This explains why identifying compiled instructions is insufficient to identify a callable's behavior.