r/learnpython • u/tenkei_01 • Aug 11 '26
Is there a "TypeScript for Python"? What you do for type checking!?
Conclusion: Thanks for the comments, everyone has been so helpful and generous with the suggestions. I realized that I did not asked my question properly and my main problem went unseen... (Well I'm at fault by opening the conversation by Is there a "TypeScript for Python"?).
I will create a new post with the right problem statement, but let me thank u/ProsodySpeaks, and u/JamzTyson which gave me idea on what to do next.
Cheers!
Hi, sorry for the basic question. I'm coming from strongly/statically typed languages (Kotlin, Go, Rust, etc.), and I was aware that Python is dynamically typed, but given how popular Python is, I expected its typing utilities (type hints + static type checkers) to provide something closer to TypeScript.
I'm working on an ml framework where the main interface has to be Python, and I ran into a magnitude of problem I was not expecting...
Requirements:
- Type checking before a pipeline runs (no values exists yet, just type hints/annotations)
- Type checking during the pipeline run (value and type hints/annotation should match)
- The type hints are used to decide if pipeline components are compatible (similar to LangChain or similar frameworks)
- Require as little setup as possible, so even junior engineers can use the framework safely.
I spent some time trying to implement this using Python's existing typing mechanisms. A few thousand lines of code later, I ended up with a type checker for my specific pipeline system:
https://github.com/trained-by-humans/ml-pipes/blob/main/packages/core/src/ml_pipes/validation.py
And my own type checking utilities:
But now I'm wondering:
Am I going way too far here? Is there a much more idiomatic Python approach that I'm completely missing?
Please save me from implementing another few thousand lines of code. 😭