Warning: Some posts on this platform may contain adult material intended for mature audiences only. Viewer discretion is advised. By clicking ‘Continue’, you confirm that you are 18 years or older and consent to viewing explicit content.
Neither of those provide type inference? Type inference is when you give the compiler only occasional type hints and it can still figure out what the types are behind the scenes.
For example:
name = "World"greeting = "Hello " + name
compile_error = greeting / 42
In a type-inferred language, the compiler would automatically know that:
the first line is of type String, because it’s trivially initiated as one.
the second line is of type String, because String + String results in a String.
the third line is non-sense, because greeting is a String and cannot be divided by a number. It could tell this before you run the program.
Mypy on the other hand can only tell these things, if you give the first two lines an explicit type hint:
name:String = "World"greeting:String = "Hello " + name
Having to do this on every line of code is extremely noisy and makes refactoring annoying. I can absolutely understand that Python folks think you get productivity gains from duck typing, if this is the version of static typing they’re presented.
And we did excessively use mypy + type hints + pydantic on my most recent Python project. These are not the silver bullet you think they are…
If you’re going to post a code example, at least check that it works. Here’s your example, with no type hints, giving me errors both from the LSP, and when trying to run via mypy: https://imgur.com/a/Hq5Y5Gt.
Neither of those provide type inference? Type inference is when you give the compiler only occasional type hints and it can still figure out what the types are behind the scenes.
For example:
name = "World" greeting = "Hello " + name compile_error = greeting / 42
In a type-inferred language, the compiler would automatically know that:
Mypy on the other hand can only tell these things, if you give the first two lines an explicit type hint:
name: String = "World" greeting: String = "Hello " + name
Having to do this on every line of code is extremely noisy and makes refactoring annoying. I can absolutely understand that Python folks think you get productivity gains from duck typing, if this is the version of static typing they’re presented.
And we did excessively use mypy + type hints + pydantic on my most recent Python project. These are not the silver bullet you think they are…
If you’re going to post a code example, at least check that it works. Here’s your example, with no type hints, giving me errors both from the LSP, and when trying to run via mypy: https://imgur.com/a/Hq5Y5Gt.