Skip to the workspace
Pebellslearn by building

Python syntax & reference

Find the form you need, compare how it behaves, and open the complete explanation when you need more depth.

Python 3.10+ syntax; individual entries identify newer features. Browser exercises use the configured Python runner.

1 matching syntax entry

Decorators and wraps

Learn in depth →

A decorator transforms a function when its definition executes. wraps preserves useful metadata.

@decorator
def function(...): ...

Example

from functools import wraps
def traced(fn):
    @wraps(fn)
    def wrapper(*args, **kwargs):
        return fn(*args, **kwargs)
    return wrapper
@traced
def total(a, b):
    return a + b
print(total(2, 3), total.__name__)

Result

5 total

Watch for: Stacked decorators apply from the bottom upward. A synchronous wrapper does not automatically await an async function.

Practise this topic →
Complete explanation index (91 lessons indexed)

Decorators

Technical sources and review date

Original Pebells examples. Reviewed 2026-10-28.

Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.