Skip to content

Latest commit

 

History

History
57 lines (36 loc) · 2.49 KB

Contribute.md

File metadata and controls

57 lines (36 loc) · 2.49 KB

So you want to create a new challange

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.

Steps

  1. Fork this project if you haven't done so

  2. Determine how difficult the challenge is. There are 4 levels: basic, intermediate, advanced, and extreme.

  3. 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.

  4. Put a question.py and a solution.py in the new directory. Here's an example question.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.

  5. Test with pyright to make sure your new challenge works as expected.

  6. (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..
  7. Create a Pull Request.