Type hints for variable first mentions - yes/no/sometimes(when?)?

Posted by sarnobat@reddit | Python | View on Reddit | 15 comments

I'm new to python from a java background. It's so easy when you are writing new code or are reading code you wrote in the last hour (e.g. during an interview).

Reading some code I wrote last week in a Colab notebook for a class notebook using some API that I'm learning (e.g. Word2Vec), it's not so easy. I don't know what operations I can perform on this variable I added but didn't name with enough information to trivially determine its type.

Java is so explicit with type declarations it makes you cry, but I'm seeing the dark side of dynamic typing.

One possible solution is to use type hints anywhere the type info is welcome (subjective I know). But is there any kind of best practice which maybe says that you should not do it to the point it just crowds your code?