Show HN: Python-Type-Challenges, master Python typing with online exercises (python-type-challenges.zeabur.app)
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!
47 comments
[ 2.0 ms ] story [ 110 ms ] threadany - https://docs.python.org/3/library/functions.html#any - Return True if any element of the iterable is true.
Any - A special kind of type is Any. A static type checker will treat every type as being compatible with Any and Any as being compatible with every type.
[0] https://docs.python.org/3/library/functions.html#any
any(), probably not. The semantic is too different.
But having to import Callable while callable is a built-in is a missed opportunity.
I don't miss Union, Optional and List.
I just went back to check and I saw that you are supposed to make some changes, which are shown in the solution, even though they are unnecessary to pass the tests.
"all functions without a return type or parameter types will implicitly default to using Any"
any - https://docs.python.org/3/library/functions.html#any - Return True if any element of the iterable is true.
Any - A special kind of type is Any. A static type checker will treat every type as being compatible with Any and Any as being compatible with every type.
For example, I was unaware of TypedDict so I searched the typing page for "typeddict" assuming there would likely be something like that.
What I got was an example containing the exact solution.
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'll also encourage people to contribute and make the challenges better.
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
I like the proposal, I can change it to showing the solution link once user has run it.
I got it to work with this code:
# Code starts here
class Stack[T]: def __init__(self) -> None: self.items: list[T]
# Code ends hereThis code has fewer changes than the solution provided, and doesn't need imports. I'm not sure the solution needs those imports either.
Perhaps the tests for that challenge should cover more cases.
In fact this is describe in the solution https://github.com/laike9m/Python-Type-Challenges/blob/main/...
I am doing
but it doesn't seem to work :(EDIT:
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.