python-decorators

What is a Python decorator?

Grammar specification

In Python’s full grammar specification this part can be found:

decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE
decorators: decorator+
decorated: decorators (classdef | funcdef | async_funcdef)

This is basically saying, decorators start with an @, can optionally have parameters, must be in a line by itself, and we can stack one or several decorators before a class or function definition.

Prev / Up / Next