TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Show HN: Python-Type-Challenges, master Python typing with online exercises

110 pointsby laike9mover 1 year ago
Hi HN, I&#x27;m excited to share Python-Type-Challenges, a collection of hands-on, interactive challenges designed to help Python developers master type annotations. Whether you&#x27;re new to type hints or looking to deepen your understanding, these exercises provide a fun and educational way to explore Python&#x27;s type system. I&#x27;d love to get your feedback and contributions!<p><a href="https:&#x2F;&#x2F;github.com&#x2F;laike9m&#x2F;Python-Type-Challenges">https:&#x2F;&#x2F;github.com&#x2F;laike9m&#x2F;Python-Type-Challenges</a>

16 comments

vsnfover 1 year ago
I got frustrated on the very first example (Basic 1: Any) because I didn&#x27;t realize that the typings library wasn&#x27;t imported by default. Maybe I should have known better, but it definitely got me.
评论 #38460396 未加载
评论 #38457708 未加载
评论 #38461471 未加载
评论 #38460488 未加载
评论 #38460984 未加载
评论 #38457801 未加载
d4rkp4tternover 1 year ago
I love the idea of these types of “unit” exercises, and koans. I am surprised there aren’t more of these. In fact koan&#x2F;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 ?
burning_hamsterover 1 year ago
I thought I knew at least the basics of typing in python but I learnt 3 new things in the first 5 minutes. Kudos, great work.
评论 #38461787 未加载
Arch-TKover 1 year ago
It would be improved if the problems weren&#x27;t just direct copies from the python documentation.<p>For example, I was unaware of TypedDict so I searched the typing page for &quot;typeddict&quot; 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.
评论 #38461694 未加载
评论 #38461697 未加载
Joeboyover 1 year ago
I&#x27;m ashamed to say I haven&#x27;t kept up, but haven&#x27;t there been big changes in typing over the last few python versions? Eg. there&#x27;s a new syntax for generic types in 3.12.
评论 #38459950 未加载
crunchbang-exclover 1 year ago
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) -&gt; None: self.items: list[T]<p><pre><code> def push(self, item: T) -&gt; 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&#x27;t need imports. I&#x27;m not sure the solution needs those imports either.<p>Perhaps the tests for that challenge should cover more cases.
评论 #38483942 未加载
dddnzzz334over 1 year ago
I am unable to do <a href="https:&#x2F;&#x2F;python-type-challenges.zeabur.app&#x2F;intermediate&#x2F;callable" rel="nofollow noreferrer">https:&#x2F;&#x2F;python-type-challenges.zeabur.app&#x2F;intermediate&#x2F;calla...</a><p>I am doing<p><pre><code> type SingleStringInput = Callable[[str], None] </code></pre> but it doesn&#x27;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.
评论 #38483945 未加载
nilslindemannover 1 year ago
<a href="https:&#x2F;&#x2F;python-type-challenges.zeabur.app&#x2F;basic&#x2F;optional" rel="nofollow noreferrer">https:&#x2F;&#x2F;python-type-challenges.zeabur.app&#x2F;basic&#x2F;optional</a> could have a better description. It does not become clear that the default value should be 0.
评论 #38483951 未加载
HNArg024over 1 year ago
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
评论 #38483977 未加载
hiAndrewQuinnover 1 year ago
I could use one of these for just about every language I work in. Go, Haskell, Python, TypeScript...
评论 #38475513 未加载
nicolaslemover 1 year ago
This is amazing and should be part of the Python documentation.
caditinpiscinamover 1 year ago
It would be nice if this included solutions, so that it could be used as a reference in addition to training. But overall it looks well put together.
评论 #38461487 未加载
satyanashover 1 year ago
This is quite useful for training people quickly and understanding how certain parts of the python `typing` module work. Thanks for making this.
Probiotic6081over 1 year ago
Interesting idea but I&#x27;ll stick to my regular 10fastfingers training regime
评论 #38483983 未加载
mock-possumover 1 year ago
Anyone know of anything similar, only in Typescript? Typing Koans?
评论 #38459458 未加载
v3ss0nover 1 year ago
it don&#x27;t mention python version. `any` is available by default in python 3.10 +
评论 #38457968 未加载
评论 #38459416 未加载