PEP 724: Stricter Type Guards

I don’t really see why that should be the case. A static analysis tool is basically just an application whose data is a program’s source code. Stability for such a tool is just as important as for any other tool, like a command-line tool that, say, converts BMP to PNG, or computes lexical statistics on a text. The thing that, in my mind, implies greater stability is the fact that something is in the stdlib. That would mean that something like mypy is free to evolve more rapidly in terms of what typing constructs it handles, but that the stdlib shouldn’t attempt to keep up with that.

I agree. This to me is the fundamental issue, and is one reason I have an overall pessimistic view of the various typing changes in Python. My perception is that the increasing spread of static typing is leading more people to spend more of their time trying to please the type checker, looking for new ways to write their code in order to chase some perceived benefit of being able to use a particular typing feature. The type checker is often not easing the work that people are already doing, but causing them to add an additional kind of work (typing-specific code gymnastics) to their load. This workload then spreads to everyone who has to interact with such code, let alone contribute to projects using typing, because it becomes part of everyone’s expectations that any work on writing Python will include some nonzero amount of typechecker wrangling.

I do wish we could stick to the original notion, which is that everything related to static typing is 100% optional in Python. To me that means that typing-related considerations should never have any influence on how code is written or what it actually does; it’s purely a convenience layered on top. It means that any proposal that envisions people refactoring their code to please a typechecker is prima facie misguided. If people want to do that, it’s their choice, but nothing in the official documentation, a PEP, the stdlib, etc., should contain even a whiff of a suggestion that anyone should ever do that.

2 Likes