Software Engineer (SDE)pythonintermediate3 interactive MCQs in app
Decorators & @property
@functools.wraps preserving metadata & signatureswrapper(*args, **kwargs) return propagation@property encapsulation
Core Concept
A decorator wraps a function/method cleanly (`fn = log_calls(fn)`) to add cross-cutting behavior (timing, auth guards, retries, caching) without duplicating boilerplate inside every function. Always write `@functools.wraps(fn)` on the inner `wrapper(*args, **kwargs)` so `__name__`, docstrings, and FastAPI/pytest signatures stay intact! `@property` exposes computed/validated getters cleanly with attribute syntax (`user.full_title`) without breaking callers if validation is added later.
Worked Example
`@wraps(fn) def wrapper(*args, **kwargs): start = perf_counter(); out = fn(*args, **kwargs); log(perf_counter() - start); return out` times any call without dropping return values or `__name__`!
Common Pitfall
omitting `@wraps(fn)` breaks FastAPI/pytest inspection and overwrites `__name__` with `"wrapper"`.
Recommended Readings & Practice
Practice Decorators & @property with 3 graded MCQs & written feedback.
Take SOARDO’s free 12-question diagnostic to see how strong you are across your target role and unlock adaptive daily missions.