Python 4 should have mandatory static typing

Hello,

if python 4 ever comes, it should have mandatory static types
it got too big to have Any everywhere and its just annoying to build somewhat reliable software without proper libs with types

keep python 3 without types and maybe everybody will be happy and if python 4 libs will be runnable on python 3 nobody will yell about anything

“Any” should be used only in some edge cases and be considered bad practice with warnings

1 Like

It sounds like your Python 4 would be the same as Python 3 with the addition of a command line option that says “error out if you find any code without type annotations”.

I myself would never use such a flag. It’s basically what mypy --strict gives you, with the admitted difference of your Python 4 being a compile-time check.

1 Like

Well yes, now its optional to use and a decent amount of code is not using it
so if it will be mandatory then there is nothing you can do but use it

and that’s a breaking change because it forces you if you want to port your code from python3,
you need to add all type annotations which is then also recursively needed from stuff you are importing and so on and so on

that’s why it has to be python4 if it should be mandatory, which in my opinion it should be

People that like and want type checking will to use annotation now.
By all means encourage people to use annotations.

But you cannot force people to use annotation this way.
They will simply keep using python 3 and refuse to update to python 4.
We all know that would be a bad outcome.

3 Likes

Optional static typing was accepted with the promise that it would be always be optional.

11 Likes

IIRC, the SC has more than once reiterated the commitment to it being optional, doubling down on this.

2 Likes

I am a firm advocate for a stronger type system, and I would never argue for mandatory typing in Python. It goes against many of the things that make Python great and would require not just a stronger type system, but removing a lot of dynamic behavior which could never be statically analyzed without redesigning the language from the ground up.

Any should be used a lot more than it actually is even in rigorously typed code. A lot of times, people don’t care about the type, but they’ve gotten bad advice that Any is bad, and have gotten overzealous in trying to remove it, this comes up quite a bit in library code and generics or higher-order functions that if typed more permissively would work entirely in an analyzable manner.

6 Likes

It’s probably simpler to just agree that Python 4 has any feature or breaking change that anyone desires…with the caveat that this all-singing all-dancing version might never happen.

3 Likes

If you want a static but Pythonic language, you can use:

  1. Nim
  2. Kotlin
  3. Go
  4. Julia+JET
  5. Any Python type checker

There’s no reason to take the option for dynamic typing away from people who need it.

4 Likes