Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aa2a7a4

Browse files
committed
From: "Tim Peters" <[email protected]>
The 1.5.1 tabnanny.py suffers an assert error if fed a script whose last line is both indented and lacks a newline: if 1: print 'oh fudge' # no newline here: The attached version repairs that.
1 parent cd5a5f6 commit aa2a7a4

3 files changed

Lines changed: 27 additions & 9 deletions

File tree

Lib/tabnanny.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
"""The Tab Nanny despises ambiguous indentation. She knows no mercy."""
44

5-
# Released to the public domain, by Tim Peters, 6 April 1998.
5+
# Released to the public domain, by Tim Peters, 15 April 1998.
66

7-
__version__ = "4"
7+
__version__ = "5"
88

99
import os
1010
import sys
@@ -270,7 +270,13 @@ def tokeneater(type, token, start, end, line,
270270
# that when the run of DEDENTs ends, the indentation of the
271271
# program statement (or ENDMARKER) that triggered the run is
272272
# equal to what's left at the top of the indents stack
273-
assert check_equal # else no earlier NEWLINE, or an earlier INDENT
273+
274+
# Ouch! This assert triggers if the last line of the source
275+
# is indented *and* lacks a newline -- then DEDENTs pop out
276+
# of thin air.
277+
# assert check_equal # else no earlier NEWLINE, or an earlier INDENT
278+
check_equal = 1
279+
274280
del indents[-1]
275281

276282
elif check_equal and type not in JUNK:

Tools/idle/tabnanny.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
"""The Tab Nanny despises ambiguous indentation. She knows no mercy."""
44

5-
# Released to the public domain, by Tim Peters, 6 April 1998.
5+
# Released to the public domain, by Tim Peters, 15 April 1998.
66

7-
__version__ = "4"
7+
__version__ = "5"
88

99
import os
1010
import sys
@@ -270,7 +270,13 @@ def tokeneater(type, token, start, end, line,
270270
# that when the run of DEDENTs ends, the indentation of the
271271
# program statement (or ENDMARKER) that triggered the run is
272272
# equal to what's left at the top of the indents stack
273-
assert check_equal # else no earlier NEWLINE, or an earlier INDENT
273+
274+
# Ouch! This assert triggers if the last line of the source
275+
# is indented *and* lacks a newline -- then DEDENTs pop out
276+
# of thin air.
277+
# assert check_equal # else no earlier NEWLINE, or an earlier INDENT
278+
check_equal = 1
279+
274280
del indents[-1]
275281

276282
elif check_equal and type not in JUNK:

Tools/scripts/tabnanny.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
"""The Tab Nanny despises ambiguous indentation. She knows no mercy."""
44

5-
# Released to the public domain, by Tim Peters, 6 April 1998.
5+
# Released to the public domain, by Tim Peters, 15 April 1998.
66

7-
__version__ = "4"
7+
__version__ = "5"
88

99
import os
1010
import sys
@@ -270,7 +270,13 @@ def tokeneater(type, token, start, end, line,
270270
# that when the run of DEDENTs ends, the indentation of the
271271
# program statement (or ENDMARKER) that triggered the run is
272272
# equal to what's left at the top of the indents stack
273-
assert check_equal # else no earlier NEWLINE, or an earlier INDENT
273+
274+
# Ouch! This assert triggers if the last line of the source
275+
# is indented *and* lacks a newline -- then DEDENTs pop out
276+
# of thin air.
277+
# assert check_equal # else no earlier NEWLINE, or an earlier INDENT
278+
check_equal = 1
279+
274280
del indents[-1]
275281

276282
elif check_equal and type not in JUNK:

0 commit comments

Comments
 (0)