[Python-bugs-list] [ python-Bugs-407626 ] Trailing white space after line continue

nobody nobody@sourceforge.net
Sat, 10 Mar 2001 21:34:04 -0800


Bugs #407626, was updated on 2001-03-10 19:03
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=407626&group_id=5470

Category: Parser/Compiler
Group: Not a Bug
Status: Closed
Priority: 5
Submitted By: Jeff Davis
Assigned to: Fred L. Drake, Jr.
Summary: Trailing white space after line continue

Initial Comment:
Trailing white space after a line continue character
(\) causes an "invalid token" error when parsing.

The trailing white space can be either tabs or spaces.

Tested against Python 2.0 and 2.1b1; error occurs in
both.

Request resolution: parser should ignore trailing white
space after line continue character

Sample code:

# ok -no trailing white space past line continue char
print	'case 1a' + \
	'case 1b'

# invalid token error - one space after line continue
char
print	'case 2a' + \ 
	'case 2b'

# invalid token error - one tab after line continue
char
print	'case 3a' + \	
	'case 3b'


----------------------------------------------------------------------

Comment By: Jeff Davis
Date: 2001-03-10 21:34

Message:
Logged In: YES 
user_id=170745

I am conviced by the consistency argument - if the standard 
definition of a line continue is literally an escaped 
newline ("\n"), and white space between the escape and the 
newline isn't valid, then clearly Python's line continue 
should follow the same rules.

I'll just run a preprocessor to tidy up my python code.

On the plus side, I looked at the source code for the first 
time.  Pretty fun.

----------------------------------------------------------------------

Comment By: Tim Peters
Date: 2001-03-10 20:58

Message:
Logged In: YES 
user_id=31435

Agree with Fred here:  not a bug.  The grammar does not 
allow for spaces after the backslash, and not only does 
Python rely on that, but also all the regexp-based parsers 
in assorted tools (from the Emacs python-mode thru IDLE).

The good news is that many tens of thousands of users have 
learned to live with this without any complaint <wink>.

Note that IDLE automatically strips trailing spaces when 
you hit ENTER; many other good programmer's editors do 
too.  The script Tools/Scripts/reindent.py will strip 
trailing spaces in "batch mode" for you.  Note also that 
backslash continuation is *unusual* in Python source code 
(just look at the megabytes of .py files that come with the 
distribution).

----------------------------------------------------------------------

Comment By: Jeff Davis
Date: 2001-03-10 19:24

Message:
Logged In: YES 
user_id=170745

Ok, I see your reasoning.  It's just annoying because while 
editing I sometimes leave trailing white space after the 
line continue, then it breaks my flow when I get an error 
and have to go back and delete a few spaces or tabs that 
don't really matter.

I'll dig through the source and see if I can change it to 
ignore trailing white space after the line continue char to 
the end of line.  I can't imagine that *not* having it 
raise an error on trailing whitespace would cause problems 
for anyone, and it would help me out.

----------------------------------------------------------------------

Comment By: Fred L. Drake, Jr.
Date: 2001-03-10 19:10

Message:
Logged In: YES 
user_id=3066

Python 1.5.2 also exhibits this behavior, and I'm fairly certain all previous versions did as well.  It's not at all clear this is a bug.  Typically, languages which use a line continuation character don't allow anything between the continuation character and the end of the physical line (in some, it's actually just an "escape" that causes the newline to be treated as any other whitespace character, as in the Unix shells).

I'm marking this "Not a bug" since there is no change in behavior or other reason to consider this an error.

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=407626&group_id=5470