shlogg · Early preview
Augustine Alul @21alul21

Unlocking Python Decorators: Simplifying Code With Syntactic Sugar

Decorators in Python: Add extra functionality to classes & functions w/o altering initial code. Think @login_required in Flask. A decorator is a func that takes another func as an arg & wraps it with mods.

Introduction:
Have you ever come across a Python code base where "@login_required" or where the "@" sign is used with any other suffix on top of a function or class and you immediately begin to wonder what it is or what is its purpose? 
Or have you in the past used a framework where the documentation says you should use a certain decorator to achieve a particular functionality but you just do not know how the implementation is done under the hood and would love to find out? 
Or maybe, it is understandable that you are new to the concept of decorators and would love to learn about it, hang in t...