Awesome, this guide will help you create a new challenge. Before diving into the details, there's an important question:
how to find an idea for a new challenge?
There are two good ways:
- Real-world problems you encountered in work and/or study;
- Every typing related PEP has numerous examples discussing different uses cases (e.g. PEP 646)
Once you come up with an idea, go to the next steps.
-
Fork this project if you haven't done so
-
Determine how difficult the challenge is. There are 4 levels: basic, intermediate, advanced, and extreme.
-
Create a new directory under
challenges/
. The new directory's name should follow the pattern[basic|intermediate|advanced|extreme]-name
.For example, say you want to add a new challenge about Protocols. Since this is an advanced topic, you may name the directory
advanced-protocol
. -
Put a
question.py
and asolution.py
in the new directory. Here's an examplequestion.py
:""" TODO: foo should accept a dict argument, both keys and values are string. """ def foo(x): pass ## End of your code ## foo({"foo": "bar"}) foo({"foo": 1}) # expect-type-error
You want to include several things in
question.py
:- Describe the challenge, make sure people understand what they need to accomplish (i.e. the
TODO:
part) - A comment
## End of your code ##
. This is mandatory, just copy and paste it. - Several test cases. Add a comment
# expect-type-error
after the lines where type errors should be thrown.
solution.py
contains the right solution, with everything else unchanged.Rule of Thumb: A challenge should NEVER ask users to write the actual implementation. Users are expected to write type hints and type hints only, and be able to pass the tests.
- Describe the challenge, make sure people understand what they need to accomplish (i.e. the
-
Test with
pyright
to make sure your new challenge works as expected. -
(Optional) Add a hint message for the challenge, A well-written HINT sometimes makes the challenge even better. Steps:
- Create a file named
hints.md
in the same directory. - Write hint message in markdown format, e.g:
Check out TypeVar, the constraints argument might be a good fit for this challenge.
.
- Create a file named
-
Create a Pull Request.