[New Concept Exercise]: Decorators
This issue describes how to implement the Decorators concept exercise for the Python track.
This has been re-worked from an older concept exercise issue, which can be found here.
The related about.md can be found here.
The links.json, introduction.md and metadata are still pending for the concept. Please see this improvement issue for more details.
β Getting started
If you have not yet created or contributed to a concept exercise, this issue will require some upfront reading to give you the needed background knowledge. Some good example exercises to look at in the repo:
π‘Example Exercisesπ‘ (click to expand)
We also recommend completing one or more of the concept exercises (they're called "learning exercises") on the website.
Please please read the docs before starting. Posting PRs without reading these docs will be a lot more frustrating for you during the review cycle, and exhaust Exercism's maintainers' time. So, before diving into the implementation, please go through the following documents:
General Contributing Docs:
- Contributing to Exercism | Exercism and GitHub | - Contributor Pull Request Guide
- What are those Weird Task Tags about?
- Exercism Formatting and Style Guide
- Exercism Markdown Specification
- Reputation
Documents on Language Tracks and Concept Exercises
- Building Language Tracks: An Overview
- What are Concept Exercises?
- Concept Exercise Specifications
- Concept Exercise Stories
π― Goal
The goal of this concept exercise is to teach an understanding/use/creation of decorators in Python.
π‘Learning objectives
- Review/understand more details on
higher-order functionsin Python- returning
functionsfromfunctions - passing a
functionas an argument to anotherfunction - inner or nested
functions
- returning
- Understand that the
decoratorform and the@symbols aresyntatic sugarfor making/callinghigher-order functions - Know that
decoratorsextend the behavior of an "inner", "wrapped", or passedfunctionwithout explicitly modifying it. - Create & use simple function
decorators - Create & use a more "complex" function
decorator - Use
*argsand**kwargsto decorate a function with different arguments - Understand that a
decoratoris not required to wrap and modify afunction, but can simplyreturnit.
π€ Concepts
-
decorators -
functions,higher-order functions -
functions as arguments -
functions as returns -
nested funcitons -
*argsand**kwargs
π« Topics that are Out of scope
Concepts & Subjects that are Out of Scope (click to expand)
-
comprehensions -
class decorators -
classesasdecorators -
functools(this will get its own exercise) -
functools.wraps -
generators -
lambda,anonymous functions -
map(),filter(), andreduce()(these will get their own exercise) - nested
decorators - stateful
decorators
β©οΈ Prerequisites
These are the concepts/concept exercises the student should be familiar with before taking on/learning this concept.
Prereqs (click to expand)
-
basics -
bools -
comparisons -
dicts -
dict-methods -
functions -
function-arguments -
higher-order-functions -
iteration -
lists -
list-methods -
numbers -
sequences -
sets -
strings -
string-methods -
tuples
π Resources for Writing and Reference
Resources (click to expand)
Exercise Ideas & Stories
Should you need inspiration for an exercise story, you can find a collection here. You can also port an exercise from another track, but please make sure to only to include tasks that actually make sense in Python and that add value for a student. Remove/replace/add tasks as needed to make the concept clear/workable.
π Exercise Files to Be Created
File Detail for this Exercise (click to collapse)
|
βΎοΈ Exercise Metadata - Track
For more information on concept exercises and formatting for the Python track config.json , please see config.json. The track config.json file can be found in the root of the Python repo.
You can use the below for the exercise UUID. You can also generate a new one via exercism configlet, uuidgenerator.net, or any other favorite method. The UUID must be a valid V4 UUID.
-
Exercise UUID :
505c7e27-a17d-4d57-961b-304555af4a32 - concepts should be filled in from the Concepts section in this issue
- prerequisites should be filled in from the Prerequisites section in this issue
πΆ Implementation Notes
-
As a reminder, code in the
.meta/examplar.pyfile should only use syntax & concepts introduced in this exercise or one of its prerequisite exercises. We run all ourexamplar.pyfiles through PyLint, but do not strictly require module docstrings. We do require function docstrings similar to PEP257. See this concept exerciseexemplar.pyfor an example. -
Please do not use comprehensions, generator expressions, or other syntax not previously covered either in the introduction to this exercise, or to one of its prerequisites. Please also follow PEP8 guidelines.
-
In General, tests should be written using
unittest.TestCaseand the test file should be named<EXERCISE-NAME>_test.py.- All asserts should contain a "user friendly" failure message (these will display on the webiste to students, so be as clear as you can).
- We use a
PyTest custom markto link test cases to exercise task numbers. - We also use
unittest.subtestto parameterize test input where/when needed. Here is an example testfile that shows all three of these in action.
-
While we do use PyTest as our test runner and for some implementation tests, please check with a maintainer before using a PyTest-specific test method, fixture, or feature.
-
Our markdown and JSON files are checked against prettier . We recommend setting prettier up locally and running it prior to submitting your PR to avoid any CI errors.
π Next Steps & Getting Help
-
If you'd like to work on this issue, comment saying "I'd like to work on this"(there is no real need to wait for a response, just go ahead, we'll assign you and put a[claimed]label on the issue). - If you have any questions while implementing, please post the questions as comments in here, or contact one of the maintainers on our Slack channel.
Hi @BethanyG π
I would like to give this issue a try now. I never worked on exercises before, so might take a while though π
Hi @velaco ππ½ !
We would be delighted to have you work on this. π Don't worry about taking a while - I've written several exercises, and they always take time to get through. Just ping if you need help, or have any questions. In particular, the tests might be complex for this exercise, and we may also want to discuss analyzer scenarios and comments.
During the writing of the concept about.md, we had a lot of back and forth about what to cover (use vs making and how complex to get with examples and tasks) - so if you get into this and decide what we need is two separate exercises, we can discuss that as well.
Hi @BethanyG Well, if you can suggest any resources that help you come up with exercise ideas, other than the existing concept exercises, I'd love to hear them π
We can discuss how many exercises we need and what to cover, that would be nice. I can ping you about that when I get some idea what kind of exercises will work for this concept.
Hi @velaco -- sincere apologies for the delay in getting back to you. I've been swamped. Let me do a little thinking, and see what I can come up with within the next couple of days. I'll post some things here as I go.
Thank you for your patience. π Hopefully, we can come up with a great exercise together.
Hi @BethanyG
No worries, this week I had to put this issue on the back-burner unfortunately, so no progress at all :( Next week should be a bit slower, so I will also look into some ideas for the exercise.
Looking forward to hearing what you come up with π
This issue has been automatically marked as abandoned π because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Is this still claimed?
@safwansamsudeen - yes, it is. As stated in the comments of the Yacht approach you are working on, we need to have a conversation (and there are a ton of documents to go through) before you tackle a concept exercise. Additionally, we have higher-priority (earlier in the concept tree) exercises we'd like to complete on the track before we loop back to things like decorators or anonymous functions.
It would be preferable if you worked on exercises hints, exercise approaches, and exercise mentor notes while we get things sorted. Thanks!
Sounds good, sure!