Every python developer I know uses an auto formatter today, and never needs to think about it (ruff, black). It's not ambiguous and is immediately visible if something has the wrong indent.
(On other projects, I often wish other languages had formatters as good and standard as the Python ecosystem. I have many complaints about Python but whitespace is just not a problem I've seen)
You missed the point. I’m well aware python has formatters, I use them and implemented my own. The point was that when generating/manipulating python code you cannot just generate in whatever format then run a formatter. you need to carefully keep track of the exact indentation at place where the code in written
Fair. That is a very slight friction on what is quite a small niche, though (compared to the wider ecosystem of developers). And most that need similar will use AST or runtime construction.
The trivial kind of raw source generation is still trivial, but I'm guessing you're doing embedding/templates or something?
If I were doing this, and the code generator was itself in Python, I'd probably use ast and/or tokenize to avoid having to manipulate literal whitespace.
Python's significant indentation does have real costs, but they mostly don't affect experienced programmers working on real codebases in real editors or IDEs. Rather, they are things like, it makes the REPL more cumbersome, and newbies sometimes find that code they copy-paste from the Web mysteriously fails to work.
Have you never tried to paste python code from the internet into an editor? At least half the time the indentation is screwed up and I have to go in and figure out manually where to put the spaces in. Indentation gets screwed up by pasting in other languages too, but with those I can generally tell the editor to reindent and it can because the information is included in the source code.
I've tried them all - vim, emacs, vscode, etc. They all fail in this regard not because of themselves but because significant whitespace is a terrible idea which nearly every programming language avoids.