exercism / python

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

[New Concept Exercise]: Class Inheritance #3096

Closed BethanyG closed 12 months ago

BethanyG commented 2 years ago

This issue describes how to implement the class-inheritance concept exercise concept exercise for the Python track. The related concept documents improvement issue can be found here.


✅ 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💡
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

This concept exercise is meant to teach an understanding/use of class-inheritance in Python.


💡Learning objectives


🤔 Concepts


🚫 Topics that are Out of scope


Concepts & Subjects that are Out of Scope (click to expand)
- `class-composition` as an explicit topic (_it is ok to use limited composition as needed in example code_) - `dataclasses` - `decorators` outside of `@property`, `@staticmethod`, and `@classmethod` (_the student should already be exposed to these in the prerequisite exercise_) - `generators` - `coroutines` - `descriptors` (_these will get their own exercise_) - using a `class` as a decorator - performance considerations


↩️ Prerequisites

These are the concepts/concept exercises the student should be familiar with before taking on/learning this concept.

Prereqs (click to expand) - `basics` - `booleans` - `classes` - `class-customization` - `comparisons` - `decorators` - `dicts` - `functions` - `higher-order-functions` - `iteration` - `lists` - `numbers` - `sequences` - `sets` - `strings` - `tuples`


📚 Resources for Writing and Reference

Resources (click to expand)
- [classes (Python tutorial)](https://docs.python.org/3/tutorial/classes.html) - [Real Python: Object-Oriented Programming in Python 3](https://realpython.com/python3-object-oriented-programming/) - [Real Python: Inheritance and Composition: A Python OOP Guide](https://realpython.com/inheritance-composition-python/) - [Towards DataScience: Understand Inheritance in Python](https://towardsdatascience.com/understand-inheritance-in-python-74f8e3025f3c) -- (_this is not a good resource for hints or links, since it requires an account signup_) - [Liskov substitution principle](https://en.wikipedia.org/wiki/Liskov_substitution_principle) - [Multiple Inheritance in Python](https://www.python-course.eu/python3_multiple_inheritance.php) - [Multiple Inheritance is Hard (Ned Batchelder)](https://nedbatchelder.com/blog/201210/multiple_inheritance_is_hard.html) - [Python.org: MRO in Python 2.3+](https://www.python.org/download/releases/2.3/mro/) - [Dig into Python super() and MRO](https://gaopinghuang0.github.io/2018/12/29/dig-into-python-super-and-mro) - [Multiple inheritance and mixin classes in Python](https://www.thedigitalcatonline.com/blog/2020/03/27/mixin-classes-in-python/) - [Making Python classes more modular using mixins](https://www.residentmar.io/2019/07/07/python-mixins.html) - [Write composable, reusable Python classes using Mixinsl)](https://dev.to/bikramjeetsingh/write-composable-reusable-python-classes-using-mixins-6lj) - [Mixins in Python and Ruby Compared](https://andrewbrookins.com/technology/mixins-in-python-and-ruby-compared/) - [Python Data Model - Python Docs](https://docs.python.org/3/reference/datamodel.html#the-standard-type-hierarchy)


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

* ### 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.
guillermodotn commented 2 years ago

Hello; I am working on this, so if you can label it as [claimed] and assign it to me will be 👌.

I was thinking about adding some class diagrams to introduction.md, I would like to ask if there is any style guideline to follow regarding graphics. Just to fit the looks of it to the rest of the page.

BethanyG commented 1 year ago

Hi @Guillermo-N 👋🏽

Apologies for the delay - I've assigned this issue to you. Thanks so much for taking it on! ✨

I was thinking about adding some class diagrams to introduction.md, I would like to ask if there is any style guideline to follow regarding graphics. Just to fit the looks of it to the rest of the page.

We really don't have a style guide for graphics. In the past (due to exercises being downloadable to a students machine), we largely shied away from graphics. So the overarching advice is to make sure that you don't solely rely on graphics to explain things, since you can't be confident that a student who has downloaded the exercise can see them. If the student has an IDE that will render a Markdown preview, they will show up in the instruction text. Otherwise, they will show as links to the GitHub repo where they are stored (more on that below). Here are some other things off the top of my head that I'd recommend:

  1. Make sure to have good alt text for each diagram/image.
  2. Try to use/save diagrams as svgs, since they'll resize much nicer in mobile and smaller-screen context.
  3. Choose colors from the surrounding page, but faded or lighter in saturation, so that they don't cause a user's eyes to "bounce" back and forth, or get tired.
  4. While we don't currently have a dark mode for the website, we will have one eventually. Try to plan graphics so that they will display nicely on both light and dark screens.
  5. Aim for "medium" size. Don't have a graphic so big it crowds out everything else. Conversely, don't have a graphic so detailed that it won't be readable on a smaller screen - in other words - don't make a graphic that will require a resize of +400% to read.

For the graphics you do include, you should upload/PR them to the V3 files repo. Once they are approved and merged there, you can link to them in your documentation here. If a graphic is approaching 1MB in size or bigger, you'll want to use the GitHub LFS system to upload them to the repo. More info on that here: https://git-lfs.github.com/

For the graphics I've included (see this exercise instructions append and the exercise hints file), I have used mermaid JS, and then saved the diagram out as SVG which worked fairly well. VS Code has extensions that can help with that process.

You can also reach out on our forum and one of the friendly community members there would be glad to help -- or you can also ping me here on GitHub, should you have more questions or issues.

guillermodotn commented 1 year ago

That is true, I didn't thought about the Markdown not be render. Because the graphics are simple I will try to do them in ASCII.

That should be okay, right?

guillermodotn commented 1 year ago

Just submitted what I think can be the a first revision.

guillermodotn commented 1 year ago

Hello @BethanyG;

Any updates or tips about what to change on the code I did summited?

BethanyG commented 1 year ago

@Guillermo-N

Hi. 🙂 Apologies for the delay in getting back to you. Unfortunately, your submission came in as we were closing this repo to contributions, and putting things on pause. You can read more about that decision here. While I'd be happy to reevaluate things in a couple of months, I am not going to be able to review your PR right now, and will be closing it with a message. I am very sorry to have to do this to you, but we do not (right now) have the bandwidth to work on this concept exercise, and need to focus on other exercises and fixes that are higher priority.