Skip to main content
Python & FastAPI Interviews Theory P0 Medium

Decorators, closures and functools.wraps

How do decorators work, how do you pass arguments to a decorator, and why is @functools.wraps essential?

Official Reference

Model Answer & Explanation

A decorator is a callable that takes a function and returns a replacement callable. Parameterized decorators add one outer factory layer returning the decorator. Without @functools.wraps(fn), the wrapper replaces __name__, __doc__, and __signature__, which breaks FastAPI route introspection, OpenAPI docs, and pytest fixtures.

Follow-up Interview Question · In what order do stacked decorators (@a above @b) execute at definition vs call time?

Module Context & References

Python & FastAPI · Popular interview theory The 20% of Python & FastAPI concepts asked in 80% of backend interviews
Personal Notes · Markdown

Technologies & Interview Topics Covered

Switch between short-term interview tracks and long-term 80/20 engineering depth to practice JavaScript internals, React rendering and hooks, timed frontend machine coding UI challenges, MeetaPro FG300, Blind 75 & NeetCode 150 DSA patterns, Python & FastAPI APIs, PostgreSQL query optimization & MVCC, Redis caching, Applied AI RAG pipelines & evaluations, and distributed system design.