Hi HN, I'm excited to share Python-Type-Challenges, a collection of hands-on, interactive challenges designed to help Python developers master type annotations. Whether you're new to type hints or looking to deepen your understanding, these exercises provide a fun and educational way to explore Python's type system. I'd love to get your feedback and contributions!<p><a href="https://github.com/laike9m/Python-Type-Challenges">https://github.com/laike9m/Python-Type-Challenges</a>
I got frustrated on the very first example (Basic 1: Any) because I didn't realize that the typings library wasn't imported by default. Maybe I should have known better, but it definitely got me.
I love the idea of these types of “unit” exercises, and koans. I am surprised there aren’t more of these. In fact koan/kata like exercises can be a great complement to documentation for open source projects. I was recently looking for a good platform to create these types of exercises. Anybody have a favorite ?
It would be improved if the problems weren't just direct copies from the python documentation.<p>For example, I was unaware of TypedDict so I searched the typing page for "typeddict" assuming there would likely be something like that.<p>What I got was an example containing the exact solution.<p>I mean, I definitely learned something new but I think it would have been better if I had to come up with my own solution on the basis of the documentation and example.
I'm ashamed to say I haven't kept up, but haven't there been big changes in typing over the last few python versions? Eg. there's a new syntax for generic types in 3.12.
The challenge generic class can be solved without making any change to the pop() function.<p>I got it to work with this code:<p># Code starts here<p>class Stack[T]:
def __init__(self) -> None:
self.items: list[T]<p><pre><code> def push(self, item: T) -> None:
self.items.append(item)
def pop(self):
return self.items.pop()
</code></pre>
# Code ends here<p>This code has fewer changes than the solution provided, and doesn't need imports. I'm not sure the solution needs those imports either.<p>Perhaps the tests for that challenge should cover more cases.
I am unable to do <a href="https://python-type-challenges.zeabur.app/intermediate/callable" rel="nofollow noreferrer">https://python-type-challenges.zeabur.app/intermediate/calla...</a><p>I am doing<p><pre><code> type SingleStringInput = Callable[[str], None]
</code></pre>
but it doesn't seem to work :(<p>EDIT:<p>I got the problem. You need a new line at the end since it seems as if it is concatenating my last line to the first line of the test.
<a href="https://python-type-challenges.zeabur.app/basic/optional" rel="nofollow noreferrer">https://python-type-challenges.zeabur.app/basic/optional</a> could have a better description. It does not become clear that the default value should be 0.
Very cool OP! Just a suggestion. I would like to always have the option to see the solution link, or at least, once I pass print what was your expected solution.<p>Like, for the optional challenge I wrote foo(x: Optional[int] = None) and it passed but your solution was simpler with x: int|None = 0