From 301626a784589cf4d8426b80c82836f3d927ddb8 Mon Sep 17 00:00:00 2001 From: Aleksandar Ratesic Date: Fri, 8 Jul 2022 16:44:10 +0200 Subject: [PATCH 1/3] Improve docs for Decorators concept --- concepts/decorators/.meta/config.json | 6 +++--- concepts/decorators/introduction.md | 8 +++++++- concepts/decorators/links.json | 24 ++++++++++++++++-------- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/concepts/decorators/.meta/config.json b/concepts/decorators/.meta/config.json index 9b9e8da5a9b..a776cb16d89 100644 --- a/concepts/decorators/.meta/config.json +++ b/concepts/decorators/.meta/config.json @@ -1,5 +1,5 @@ { - "blurb": "TODO: add blurb for this concept", - "authors": ["bethanyg", "cmccandless"], - "contributors": [] + "blurb": "Decorators are higher-order functions that take other functions as arguments to extend/modify their behavior and return the modified functions. They can be applied to classes as well, in which case they will take a class as an argument instead of a function.", + "authors": ["BethanyG", "bobahop", "kotp", "mathstrains21"], + "contributors": ["velaco"] } diff --git a/concepts/decorators/introduction.md b/concepts/decorators/introduction.md index fcde74642ca..e17128a3df8 100644 --- a/concepts/decorators/introduction.md +++ b/concepts/decorators/introduction.md @@ -1,2 +1,8 @@ -#TODO: Add introduction for this concept. +# Introduction +Functions are first-class objects in Python, which means they can also be passed as arguments to other functions. +Decorators are [higher-order functions][hofunc] that take another function as an argument and return it after extending or modifying its behavior. +Decorators are defined in the same way as any other function, but they are applied on the line above the functions they are decorating using the `@` symbol before their names (`@my_decorator`). While they can take multiple arguments, decorators must take _at least_ the function they are decorating as an argument. +They can also be applied to class methods and even whole classes for the same reason - to extend them or modify their behaviors. + +[hofunc]:https://en.wikipedia.org/wiki/Higher-order_function diff --git a/concepts/decorators/links.json b/concepts/decorators/links.json index eb5fb7c38a5..76a770b5aa1 100644 --- a/concepts/decorators/links.json +++ b/concepts/decorators/links.json @@ -1,18 +1,26 @@ [ { - "url": "http://example.com/", - "description": "TODO: add new link (above) and write a short description here of the resource." + "url": "https://peps.python.org/pep-0318/", + "description": "PEP 318 – Decorators for Functions and Methods" }, { - "url": "http://example.com/", - "description": "TODO: add new link (above) and write a short description here of the resource." + "url": "https://peps.python.org/pep-3129/", + "description": "PEP 3129 – Class Decorators" }, { - "url": "http://example.com/", - "description": "TODO: add new link (above) and write a short description here of the resource." + "url": "https://www.geeksforgeeks.org/first-class-functions-python/", + "description": "First Class Functions in Python" }, { - "url": "http://example.com/", - "description": "TODO: add new link (above) and write a short description here of the resource." + "url": "https://www.geeksforgeeks.org/higher-order-functions-in-python/", + "description": "Higher Order Functions in Python" + }, + { + "url": "https://realpython.com/primer-on-python-decorators/", + "description": "Primer on Python Decorators" + }, + { + "url": "https://www.geeksforgeeks.org/chain-multiple-decorators-in-python/", + "description": "Chain Multiple Decorators in Python" } ] From 25f61b4f9c7b382cc186a06a4f6383f3b2a3bd4b Mon Sep 17 00:00:00 2001 From: Aleksandar Ratesic Date: Mon, 11 Jul 2022 17:03:07 +0200 Subject: [PATCH 2/3] Remove class decorators from concept docs. --- concepts/decorators/.meta/config.json | 2 +- concepts/decorators/introduction.md | 1 - concepts/decorators/links.json | 4 ---- 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/concepts/decorators/.meta/config.json b/concepts/decorators/.meta/config.json index a776cb16d89..5f459dbce98 100644 --- a/concepts/decorators/.meta/config.json +++ b/concepts/decorators/.meta/config.json @@ -1,5 +1,5 @@ { - "blurb": "Decorators are higher-order functions that take other functions as arguments to extend/modify their behavior and return the modified functions. They can be applied to classes as well, in which case they will take a class as an argument instead of a function.", + "blurb": "Decorators are higher-order functions that take other functions as arguments to extend/modify their behavior and return the modified functions.", "authors": ["BethanyG", "bobahop", "kotp", "mathstrains21"], "contributors": ["velaco"] } diff --git a/concepts/decorators/introduction.md b/concepts/decorators/introduction.md index e17128a3df8..5bfc4720f20 100644 --- a/concepts/decorators/introduction.md +++ b/concepts/decorators/introduction.md @@ -3,6 +3,5 @@ Functions are first-class objects in Python, which means they can also be passed as arguments to other functions. Decorators are [higher-order functions][hofunc] that take another function as an argument and return it after extending or modifying its behavior. Decorators are defined in the same way as any other function, but they are applied on the line above the functions they are decorating using the `@` symbol before their names (`@my_decorator`). While they can take multiple arguments, decorators must take _at least_ the function they are decorating as an argument. -They can also be applied to class methods and even whole classes for the same reason - to extend them or modify their behaviors. [hofunc]:https://en.wikipedia.org/wiki/Higher-order_function diff --git a/concepts/decorators/links.json b/concepts/decorators/links.json index 76a770b5aa1..dfaa663c436 100644 --- a/concepts/decorators/links.json +++ b/concepts/decorators/links.json @@ -3,10 +3,6 @@ "url": "https://peps.python.org/pep-0318/", "description": "PEP 318 – Decorators for Functions and Methods" }, - { - "url": "https://peps.python.org/pep-3129/", - "description": "PEP 3129 – Class Decorators" - }, { "url": "https://www.geeksforgeeks.org/first-class-functions-python/", "description": "First Class Functions in Python" From 1ec3b1b9d58a8d9c2984d6039d7524fac16651a2 Mon Sep 17 00:00:00 2001 From: BethanyG Date: Mon, 11 Jul 2022 13:31:13 -0700 Subject: [PATCH 3/3] Update concepts/decorators/.meta/config.json --- concepts/decorators/.meta/config.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/concepts/decorators/.meta/config.json b/concepts/decorators/.meta/config.json index 5f459dbce98..57692af26e6 100644 --- a/concepts/decorators/.meta/config.json +++ b/concepts/decorators/.meta/config.json @@ -1,5 +1,5 @@ { "blurb": "Decorators are higher-order functions that take other functions as arguments to extend/modify their behavior and return the modified functions.", - "authors": ["BethanyG", "bobahop", "kotp", "mathstrains21"], - "contributors": ["velaco"] + "authors": ["BethanyG", "bobahop", "kotp", "mathstrains21", "velaco"], + "contributors": [] }