Indentation style...

Bernhard Herzog bh at intevation.de
Tue May 29 05:43:30 EDT 2001


"Alex Martelli" <aleaxit at yahoo.com> writes:

> "Emile van Sebille" <emile at fenx.com> wrote in message
> news:9etto3$15aqa$1 at ID-11957.news.dfncis.de...
> > From the Python Language Reference:
> > """2.1.7 Indentation
>     ...
> > First, tabs are replaced (from left to right) by one to eight spaces such
> > that the total number of characters up to and including the replacement is
> a
> > multiple of eight (this is intended to be the same rule as used by Unix).
>     ...
> > > # tab-width:4
> > >
> > > def f():
> > >     a = 1      # four spaces indent
> > > b = 2  # one tab indent
> > >
> > > The Python tokenizer recognizes various forms of the tab-width comment.
> > > I'm not sure it's documented anywhere except in the sources.
> 
> I think 2.1.7 is lying -- the tokenizer DOES look for various kind
> of Emacs, vi and vim tab-setting indications, and those, if found,
> override the normal setting of tab width as 8.  If 2.1.7 was right,
> the example function would break... and yet it does work.

The Language Reference and the actual implementation (of CPython)
differ, so that's either a Bug in the docs or in Python.

IMO the implementation should be changed to match the documentation. The
tab-width settings usually affect only one editor, so many people
reading the code will see a different tab-width than the Python
tokenizer or the original developer. Add to that that the Python
tokenizer is far more tolerant in recognizing the settings than the
editors. For instance, the snippet I posted (i.e. the one quoted above)
works in Python, but Emacs does not recognize the settings as they are,
you'd have to use the line

# -*- tab-width:4 -*-

instead. 


  Bernhard

-- 
Intevation GmbH                                 http://intevation.de/
Sketch                                 http://sketch.sourceforge.net/
MapIt!                                               http://mapit.de/



More information about the Python-list mailing list