I doubt many people picked Python "because it has types". It was picked because it was the right tool for the job.
Type hints were bolted on after the fact, and even in their limited form provide TONS of value for some people (myself included).
If you don't want them don't use them, but I doubt there is a project which uses Python specificially because it has type hints.
I think in a lot of cases only the more general form of this statement is true, i.e.:
- it is a tool
- it was picked
- there was a job
For me, that's the benefit of typing in python (as shonky as it is) -- you can use it to help write better library code, then ignore the types (except as accurate documentation) when using those libraries.
Maybe there are other languages that can do this, but the ones i know all have their own downsides.
You obviously don't get the haskell experience, where if your program type checks it's probably correct, but the alternative (if, remember, you want a dynamically typed scripting language) is no type checking, which is definitely worse for some people.
Running pyright in CI/CD and in vscode has considerably improved the quality of my code, especially when refactoring.
I do strongly believe that leaving the type checking to a third party program is a terrible idea. I also believe that it should at least be possible to opt-in to type-checking the annotations at runtime during execution (at the very least for tests).
The way python does it is different. There's no "typethon". The python grammar was simply extended to allow any random expression as a "type".
In fact:
x: print("hi") = 4
is valid python, and it does print "hi" without even so much as a warning. Personally, I don't think "print(hi)" should be a valid type.The fact that the typescript implementation does not run typescript directly, and cPython does not type check before running the code, are both implementation details.
Typescript is just a better type system on top of javascript than python's type system is on top of untyped python, because typescript is a cohesive design rather than a collection or random stuff accumulated over time.
There's no reason that couldn't have happened for python, it just didn't.
As stated in the typing documentation [0]: "the only legal parameters for type are classes, Any, type variables, and unions of any of these types".
I can put that in main.py and do `python3 main.py` and it will simply run fine.
What is the point of this whole system if it's not enforced?
If you don't want type checking, don't run mypy.
I don't see what's so difficult. If it was technically possible to run programs that have type errors in other languages, they would have the option to ignore type errors too, because it's convenient.
Typescript also ignores errors (generating js output for you to run) by default, so what's the point if it's not enforced?
And it isn't:
a.py:1: error: Invalid type comment or annotation [valid-type]
a.py:1: note: Suggestion: use print[...] instead of print(...)
Found 1 error in 1 file (checked 1 source file)PHP has been able to add in more typing over the same period of time and has seemed to avoid these Python problems.
Do you mean mypy is optional?
At the risk of opening a can of worms here, what's "horrible"?
In your own PHP code, you can get by without any typing at all. If/when you start to use 3rd party libraries, that may become a factor, though off the top of my head I can't think of a show stopper.
Python also broke backwards compatibility with their v3 release years ago. Unsure why breaking backward compatibility is being called out here(?).
But yeah, overall, it's struck me that PHP has introduced more and stricter typing rules with surprisingly little impact (compared to what could have been, of course).