7 Comments
Jun 21, 2023Liked by Avi Chawla

Hey, been following your content for a while and it’s awesome. Keep going until it reaches the vast community.

Expand full comment

Could there be a future where Python is made more type safe just like Typescript did for javascript? I think it would be better being built into Python itself as an option, rather than dividing the user base into those who want a "typescript-like" experience and those who prefer classic Python.

Expand full comment
author

I doubt that will ever happen. I have listened to a handful of talks by Guido van Rossum (and other developers of Python) and they say that don't want to drift Python away from being a dynamically typed language. So what we are expected to see is open-source libraries (like Typeguard) embedding this functionality.

Expand full comment
Jun 23, 2023Liked by Avi Chawla

Hi Avi, your post are super interesting even for readers who are not 100% into data science! Keep on! On your note and on the post on type hint enforcement : Can you detail a bit on what can be detected at stage of static code checking VS. at runtime?

Thanks

Christoph

Expand full comment
author

That's a great question, Chris :)

Static type checkers primarily analyse types using type annotations. So they will catch errors where you mistakenly pass a wrong type argument to a function, or if you assign an conflicting type to a variable, etc.

But static type checkers don't run the code and there are some errors that can only be detected at run-time. For instance, having a conflicting input from disk/user will go undetected by static type checker.

Expand full comment

Hi Avi, thanks for getting back on this. I was not precise, sorry for that. I actually was curious about TypeGuard. It's not clear to me whether it's only statically checking the type hints and then enforcing what it has found (which already is pretty helpful) or whether it does some more dynamic analysis (while acknowledging the fact that it cannot fully control all dynamic input)

Expand full comment
author

Ohh alright, I misinterpreted your question.

Typeguard primarily provides run-time type checking. So each stage of your pipeline, it is consistently verifying the data types. You can read some more details here, Chris https://typeguard.readthedocs.io/en/latest/index.html. I think this page depicts pretty well what it has to offer.

Expand full comment