Closed BethanyG closed 4 years ago
@mohanrajanr - all yours! LMK if you have questions or issues.
@cmccandless - when you get a chance, if you could give this a quick "sniff test" as a concept/issue & LMK if we need to edit it that would be awesome. Thank you.
Link to the PR Here: https://github.com/exercism/v3/pull/2312
@cmccandless - when you get a chance, if you could give this a quick "sniff test" as a concept/issue & LMK if we need to edit it that would be awesome. Thank you.
My thoughts:
Learning objectives
section feels like it's too much for a single exercise. Maybe move Functional API and aliases/@unique
to "Out of scope"?enumerate
is not the same thing as Enum
; someone new to Python might learn Enum
, then see enumerate
and get confused.Excellent feedback, @cmccandless . Thank you. I went ahead and merged the PR, but will be filing some improvement issues as I go back through our existing exercises and fill in concept docs, re-title, etc. etc. Makes sense to move @unique
out, as well as aliases. I think the Functional API
, being an alternative and shorter constructor should stay.
And we definitely want the Enum
vs enumerate()
distinction in the after.md
or approaches.md
.
PR #2312 Has been merged. Closing this issue.
This issue describes how to implement the
Enum
concept exercise for the Python track.Getting started
Please 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 read up on the following documents:
Please also watch the following video:
Goal
The goal of this exercise is to teach the student how
Enums
(Enumerations) are implemented & used in Python. We will teach this through PythonsEnum
class/type.Learning objectives
What is an
enumeration
/enum
is, and why they are needed/wanted in Python?Understand the nomenclature (naming) used in reference to
enums
(e.g.enumeration
/enum
,enum members
, enum membernames
, and enum membervalues
)Understand that
enumeration members
are functionallyconstants
(and therefore should be formatted as such)How
Enums
are different from other, more generic Python classes.How to create various
Enums
class
syntax by importing & subclassingEnum
.enum members
withvalues
that include non-int types (likestr
,tuple
,float
etc.)auto()
function to automatically assign integer values to members when exactvalue
types are unimportant/not needed.value
to differentnames
(two differentnames
can have the samevalue
; the second name defined becomes an alias of the first)@enum.unique
to prevent member aliases and enforce that membervalues
be unique.How to use an
enumeration
andenumeration members
in other functions/codeEnum members
are iterable in member definition order, but iteration will not include aliases.__members__.items()
enumeration members
are compared by identity, using theis
/is not
keywords<
,>
,<=
, '>=) between
enumeration valuesis not supported, and will throw a
TypeError`.==
and!=
can be used.enumeration values
andnon-enumeration values
will always returnFalse
Out of scope
enum
subtype (perhaps better as an advanced exercise that includes bitwise operations)enum
by being comparable toint
)Enums
__new__()
to customize the value of anenum
member (better for an advanced/extended enum exercise)enum
auto()
Concepts
Prerequisites
decorators
,@
__init__()
classes
,OOP
inheritance
iteration
iterables
dunder methods
comparisons
rich comparisons
class attributes
importing
aliasing
dicts
,dict methods
(specificallydict.items()
)mapping types
immutable
,immutability
class properties
Resources to refer to
Enums
concept exerciseEnum
Hints
Should be focused on basic definition & use, and refer to one or more of the Python related links above (or equivalent/analogous links).
After
Some links and extended discussion of what problems an enumeration type is trying to solve in python programming might be useful to the student here. In particular, the rejected PEP354, and the subsequent accepted PEP435, as well as other discussion and links from the resources section.
It might also be useful to point the student toward all the rich customization options available for
enum
, such as the "interesting examples" section of the docs.Finally, some discussion, links and usage around the "out of scope" cases above could be great to encourage the student to explore
enums
even further.Representer
TBD
Analyzer
TBD
Implementing
Tests should be written using unittest.TestCase (we try to avoid using PyTest specific features), & the test file shoul dbe named
enum_test.py
.Help
If you have any questions while implementing the exercise, please post the questions as comments in this issue, and/or reach out on the
#python-maintainers
channel in the exercism Slack team.