← Back to context

Comment by corethree

2 years ago

Conventions are changing. Modern python is shifting to type checking with external type checkers.

The two are not incompatible. I'll type all class properties and functions, but still use try/except on dict access or function calls.

  • It's not about incompatibility it's about safety. You drive with air bags or you don't, those two concepts are NOT about incompatibility. It doesn't even make sense.

    If there are situations where you have no choice but to drive without airbags, those are holes in safety.

    Essentially if you have to have runtime checks to prevent the program from full on crashing those are holes. Not everything is checkable with static checks but the way to go is to move as much of your code away from runtime checks as much as possible.

    • Not sure I understand your point, there will always be runtime checks in any non-trivial application. Typically these will be for things outside of the code, for example: network status, file access, user input, external input (think JSON parsing), hardware requirements, etc

      So for opening a file for example, using try/except instead of checking if the file exist and is readable first.

      Both achieve the same results but the first is more "pythonic".

      My point is that this way of writing code is not at all incompatible with using a type checker for said code.

      1 reply →