exercism / python

Exercism exercises in Python.
https://exercism.org/tracks/python
MIT License
1.86k stars 1.26k forks source link

[New Concept Exercise]: Decorators #3119

Closed BethanyG closed 9 months ago

BethanyG commented 2 years ago

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)
1. [Little Sister's Vocabulary](https://github.com/exercism/python/tree/main/exercises/concept/little-sisters-vocab) 2. [Meltdown Mitigation](https://github.com/exercism/python/tree/main/exercises/concept/meltdown-mitigation) 3. [Making the Grade](https://github.com/exercism/python/tree/main/exercises/concept/making-the-grade) 4. [Ellen's Alien Game](https://github.com/exercism/python/tree/main/exercises/concept/ellens-alien-game)

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:

Documents on Language Tracks and Concept Exercises

🎯 Goal

The goal of this concept exercise is to teach an understanding/use/creation of decorators in Python.


πŸ’‘Learning objectives


πŸ€” Concepts


🚫 Topics that are Out of scope


Concepts & Subjects that are Out of Scope (click to expand)
- `comprehensions` - `class decorators` - `classes` *as* `decorators` - `functools` (_this will get its own exercise_) - `functools.wraps` - `generators` - `lambda`, `anonymous functions` - `map()`, `filter()`, and `reduce()` (_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)
- [Python Docs: Defining Functions](https://docs.python.org/3/tutorial/controlflow.html#defining-functions) - [Python Docs: Term - decorator](https://docs.python.org/3/glossary.html#term-decorator) - [Functions as Objects in Python](https://medium.com/python-pandemonium/function-as-objects-in-python-d5215e6d1b0d) - [Composing Programs: Higher-Order Functions](https://composingprograms.com/pages/16-higher-order-functions.html) - [Real Python: Primer on Python Decorators](https://realpython.com/primer-on-python-decorators/) - [Dan Bader: Python Decorators: A Step-by-Step Introduction](https://dbader.org/blog/python-decorators) - [Learn by Example: Python Decorators](https://www.learnbyexample.org/python-decorators/) - [PEP 0318 (Python.org)](https://www.python.org/dev/peps/pep-0318/)


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 `introduction.md` For more information, see [**Exercise** `introduction.md`](https://github.com/exercism/docs/blob/main/building/tracks/concept-exercises.md#file-docsintroductionmd) - This can summarize/paraphrase the linked concept documents if they have already been created (either the `about` or the `introduction`). The summary does need to have enough information and examples for the student to complete all the tasks outlined for this concept exercise. * ### Exercise `instructions.md` For more information, see [`instructions.md`](https://github.com/exercism/docs/blob/main/building/tracks/concept-exercises.md#file-docsinstructionsmd) Instructions for an exercise usually center on a story that sets up the code challenge to be solved. You can create your own story, or fork one from the ones listed [here](https://exercism.org/docs/building/tracks/stories). Please make sure to give credit to the original authors if you use a story or fork an exercise. * ### Exercise `Exemplar.py` Solution For more information, see [exemplar implementation](https://github.com/exercism/docs/blob/main/building/tracks/concept-exercises.md#file-exemplar-implementation). This file should not use syntax or datas structures not introduced in this exercise or in this exercise's prerequisites. It will be used as an "ideal" solution for the challenge, so make sure it conforms to PEP8 and other formatting conventions, and **does not use single letter variable names**. It should also include proper module and function-level docstrings. However, it should **NOT** include typehinting or type aliases. * ### `.py` (Stub) for Implementation For more information, see [stub implementation](https://github.com/exercism/docs/blob/main/building/tracks/concept-exercises.md#file-stub-implementation). This file should provide the expected function names imported for testing, and optionally TODO comments and or docstrings to aid the student in their implementation. TODOs and docstrings are not required. * ### `_Test.py` Files For more information, see [Tests](https://github.com/exercism/docs/blob/main/building/tracks/concept-exercises.md#file-tests). Additionally, please note that Python associates exercise tasks to tests via a [Pytest Marker](https://docs.pytest.org/en/7.1.x/example/markers.html), and uses [`unittest subtests`](https://docs.python.org/3/library/unittest.html#subtests) as a form of test paramaterization. See the test file for [`Little Sisters Vocab`](https://github.com/exercism/python/blob/main/exercises/concept/little-sisters-vocab/strings_test.py) for examples of how these techniques work. * ### Exercise `Hints.md` For more information on writing hints see [`hints.md`](https://github.com/exercism/docs/blob/main/building/tracks/concept-exercises.md#file-docshintsmd) - Hints should provide enough information to get most students "un-stuck" and moving toward a solution. They should **not** provide a student with a direct solution. - You can refer to one or more of the resources linked in this issue above, or analogous resources from a trusted source. We prefer using links within the [Python Docs](https://docs.python.org/3/) as the primary go-to, but other resources listed above are also good. Please try to avoid paid or subscription-based links if possible. * ### Exercise Metadata Files Under `.meta/config.json` For more information on exercise `.meta/` files and formatting, see [concept exercise metadata files](https://github.com/exercism/docs/blob/main/building/tracks/concept-exercises.md#metadata-files) * `.meta/config.json` - see [this link](https://github.com/exercism/docs/blob/main/building/tracks/concept-exercises.md#file-metaconfigjson) for the fields and formatting of this file. * `.meta/design.md` - see [this link](https://github.com/exercism/docs/blob/main/building/tracks/concept-exercises.md#file-metadesignmd) for the formatting of this file. Please use the **Goal**, **Learning Objectives**,**Concepts**, **Prerequisites** and , **Out of Scope** sections from this issue.


♾️ 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.


🎢 Implementation Notes


πŸ†˜ Next Steps & Getting Help

  1. 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).
  2. 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.
velaco commented 2 years ago

Hi @BethanyG πŸ‘‹

I would like to give this issue a try now. I never worked on exercises before, so might take a while though πŸ˜…

BethanyG commented 2 years ago

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.

velaco commented 2 years ago

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.

BethanyG commented 2 years ago

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.

velaco commented 2 years ago

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 πŸ˜„

github-actions[bot] commented 1 year ago

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.

safwansamsudeen commented 1 year ago

Is this still claimed?

BethanyG commented 1 year ago

@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!

safwansamsudeen commented 1 year ago

Sounds good, sure!