4 ms·
I'm sure you know this, but just to explain "optionally typed" a bit more, Python objects are always strongly typed (can't add a string and an int together like
by greenshackle2 7y ago
I'm sure you know this, but just to explain "optionally typed" a bit more, Python objects are always strongly typed (can't add a string and an int together like in JS, etc.), by default Python variables are not typed - a variable can refer to objects of different types at different times.
Python 3 has introduced syntax to optionally declare types in the source (type annotations). This does not affect the runtime. Mypy is a program that does static analysis to tell you where your code is inconsistent with your type annotations, so:
a: int = "foo"
Will compile to bytecode and run fine, but if you run mypy it will warn you that you're not supposed to assign a string to a.