[New Concept Docs]: Dataclasses in Python
This issue describes how to implement the dataclasses in Python concept docs.
You can find the related concept exercise issue here
If you have not yet contributed to concept documents, this issue will require some upfront reading to give you the needed background knowledge.
â Getting started
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.
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 Concepts:
đ¯ Goal
These concept docs are meant to teach an understanding/creation/use of dataclasses in Python.
đĄ Learning objectives
- more fully understand the uses (and possible abuses) of
classesin Python - learn some good use-cases for
dataclassesover standardclasses - understand when and when not to use
dataclasses - create/use
dataclassesand the@dataclassdecorator - learn some additional methods from the
dataclassmodule-
dataclasses.fields -
dataclasses.asdict&dataclasses.astuple -
dataclasses.replace - default factory functions
- inheritance
-
- Contrast
dataclasseswith an alternative,collections.namedtuple- pros and cons of each method for creating data-focused
classes - speed, memory, and typing use considerations
- pros and cons of each method for creating data-focused
đĢ Out of scope
Concepts & Subjects that are Out of Scope (click to open)
-
class-inheritance,multiple-inheritance,__super()__, classmixins(these all have their own exercises) -
class-composition-- (beyond the composition needed for the decorators in this exercise) -
collectionsmodule, outside of what is needed to contrastdataclasseswithcollections.namedtuple(thecollectionsmodule will get its own exercise) -
comprehensions -
coroutines -
decoratorsoutside of@dataclass -
descriptors(these will get their own exercise) -
generators -
higher-order functions - using a
classas a decorator, beyond the methods made available fordataclasses -
type aliases -
type annotations, beyond what is used indataclasses
đ¤ Concepts
Concepts & Related Concepts Covered (click to open)
-
classes -
class attributes -
class members -
dataclasses,@dataclass -
decorators -
collections.namedtuples()
âŠī¸ Prerequisites
These are the concepts/concept exercises the student should be familiar with before taking on/learning this concept.
Prereqs (click to open)
-
basics -
booleans -
classes -
class-customization -
class-inheritance -
class-composition -
comparisons -
decorators -
dicts -
higher-order functions -
iteration -
lists -
numbers -
sequences -
sets -
strings -
tuples
đ Resources to refer to
Resources (click to open)
- classes (Python tutorial)
- Python Docs: dataclasses
- Python Docs: collections.namedtuple()
- PEP 0557
- PEP 0526
- Real Python: Data Classes in Python 3.7+ (Guide)
- Dan Bader: Writing Clean Python with Namedtuples
- Trey Hunner: Easier Classes - Python Classes without All the Cruft
- SO: What are data classes and how are they different?
-
DataClass vs NamedTuple vs Object: A Battle of Performance in Python -- warning, this is a subscription service, so not great for
links.json - Real Python: Object-Oriented Programming in Python 3
đ Files to Be Created
File Detail for this Exercise (click to collapse)
|
Please see the following for more details on these files: concepts
|
đļ Implementation Notes
- Example code should only use syntax & concepts introduced within these docs or one of the prerequisite concept exercises or documents. Where possible, please use REPL formatting, unless you are demonstrating pseudo code or a long code block. Please do not use syntax not previously covered in prerequisite topics or exercises. Please also follow PEP8 guidelines.
- 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.