[Python-Dev] Fun with whitespace

Tim Peters tim.peters at gmail.com
Wed Jul 21 05:52:11 CEST 2004

[Kurt B. Kaiser]
> I'm thinking that it might be a good idea to modify IDLE to use
> four-space indenting only, and remove the Tab options from the
> configuration dialog.

The conceptual disconnect here comes from the IDLE shell window, which
still defaults to using hard tabs.  This appears to be a consequence
of setting (the conceptual) sys.PS2 to an empty string but (the
conceptual) sys.PS1 to a 4-character string, so that continued lines
"don't look right" in the shell unless hard tabs are used.  I dislike
this so much that I avoid using the shell window most days -- I'd
rather it looked "just like" a command-line shell.

> Right now, every time a program is Run/F5, IDLE runs a version of
> tabnanny on it and then runs a syntax check.  We could add a
> reindent.py check after tabnanny (if tabnanny fails, the user is notified
> to fix things first).  Indents would be normalized at 4 spaces, and if
> an error was detected, a dialog would warn the user that the file
> would be changed.  The user could confirm (auto fix) or cancel and fix
> things manually.

I know Guido wants IDLE to whine whenever it's about to save a code
file, but that dialog is a PITA.  I sure don't want two of 'em!  I
vote for a silent revolution, where you add a secret "don't whine at
me about any changes you make when I hit F5 -- just do it and leave me
alone" option that only I know about <wink>.

> I've tried to use IDLE to convert tab-indented code to space-indented,
> but it's never worked well for me.  If you set the wrong number of
> spaces/tab the code gets scrambled.  reindent.py seems to work fine.
> Are there situations in which it can fail, assuming tabnanny is happy?

None are known.  All of Python has been run through it now <wink>, and
all of Zope3 was run through it many months ago w/o problems.  If you
*don't* check the syntax first, it can be baffling, because
tokenize.py can be baffling.  For example, if you have an extra left
paren on some line, tokenize is likely to produce an incomprehensible
exception at the end of the file, claiming that it hit EOF in an
unterminated string.

> The implementation would continue to create the .bak file.  Alternatively,
> maybe the undo capability could be extended to cover the reindent.  Or
> both.
> Is it time for IDLE to enforce four-space indentation?  Any opinions?

4-space is all I ever use -- except in the shell window.  So have to
leave objections to someone insane ...

More information about the Python-Dev mailing list