Understanding Python's __code__ object and its attributes
This is a hard Python language-knowledge question that tests deep familiarity with the internals of function objects. It asks you to distinguish between the actual attributes exposed by the __code__ object—the compiled bytecode representation of a function—and plausible but non-existent ones.
Candidates need to know what metadata the interpreter stores about a function's code: argument counts, variable names, bytecode instructions, line number mappings, and flags that describe the function's behaviour. This matters in roles involving metaprogramming, bytecode analysis, or performance profiling, where you might inspect or manipulate functions at runtime. The question rewards precise knowledge of Python's introspection API over guessing.
- The structure and purpose of code objects in the Python data model
- Distinction between function attributes and code object attributes
- Common use cases for inspecting
__code__ in production systems