Skip to content

Commit 8b85383

Browse files
dc366slozier
andauthored
Remove -t and -tt functionality from ironpython (#1131)
* Inactivate -t and -tt options, including deleting help notes * Remove sys.flags.tabcheck * Remove references to IndentationInconsistencySeverity * Remove code that is no longer referenced * Fix to check indentation every time ReadNewline is called * initialize IndentFormat in State constructor * Fix test failures Co-authored-by: Stéphane Lozier <slozier@users.noreply.github.com>
1 parent 2ec4664 commit 8b85383

10 files changed

Lines changed: 42 additions & 148 deletions

File tree

Src/IronPython/Compiler/Parser.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ private static Parser CreateParserWorker(CompilerContext context, PythonOptions
117117
Tokenizer tokenizer = new Tokenizer(context.Errors, compilerOptions, verbatim);
118118

119119
tokenizer.Initialize(null, reader, context.SourceUnit, SourceLocation.MinValue);
120-
tokenizer.IndentationInconsistencySeverity = options.IndentationInconsistencySeverity;
121120

122121
Parser result = new Parser(context, tokenizer, context.Errors, context.ParserSink, compilerOptions.Module);
123122
result._sourceReader = reader;

Src/IronPython/Compiler/Tokenizer.cs

Lines changed: 10 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ public sealed partial class Tokenizer : TokenizerService {
3232
private bool _disableLineFeedLineSeparator;
3333
private SourceUnit _sourceUnit;
3434
private ErrorSink _errors;
35-
private Severity _indentationInconsistencySeverity;
3635
private bool _endContinues;
3736
private List<int> _newLineLocations;
3837
private SourceLocation _initialLocation;
@@ -127,17 +126,6 @@ public override ErrorSink ErrorSink {
127126
}
128127
}
129128

130-
public Severity IndentationInconsistencySeverity {
131-
get { return _indentationInconsistencySeverity; }
132-
set {
133-
_indentationInconsistencySeverity = value;
134-
135-
if (value != Severity.Ignore && _state.IndentFormat == null) {
136-
_state.IndentFormat = new StringBuilder[MaxIndent];
137-
}
138-
}
139-
}
140-
141129
public bool IsEndOfFile {
142130
get {
143131
return Peek() == EOF;
@@ -1321,70 +1309,11 @@ public bool EndContinues {
13211309
}
13221310
}
13231311

1324-
/// <summary>
1325-
/// Returns whether the
1326-
/// </summary>
1312+
// <summary>
1313+
// Returns whether the
1314+
// </summary>
13271315
private bool ReadNewline() {
1328-
// Check whether we're currently scanning for inconsistent use of identation characters. If
1329-
// we are we'll switch to using a slower version of this method with the extra checks embedded.
1330-
if (IndentationInconsistencySeverity != Severity.Ignore)
1331-
return ReadNewlineWithChecks();
1332-
1333-
int spaces = 0;
1334-
while (true) {
1335-
int ch = NextChar();
1336-
1337-
switch (ch) {
1338-
case ' ': spaces += 1; break;
1339-
case '\t': spaces += 8 - (spaces % 8); break;
1340-
case '\f': spaces = 0; break;
1341-
1342-
case '#':
1343-
if (_verbatim) {
1344-
BufferBack();
1345-
MarkTokenEnd();
1346-
return true;
1347-
} else {
1348-
ch = ReadLine();
1349-
break;
1350-
}
1351-
default:
1352-
BufferBack();
1353-
1354-
if (GroupingLevel > 0) {
1355-
return false;
1356-
}
1357-
1358-
MarkTokenEnd();
1359-
1360-
// if there's a blank line then we don't want to mess w/ the
1361-
// indentation level - Python says that blank lines are ignored.
1362-
// And if we're the last blank line in a file we don't want to
1363-
// increase the new indentation level.
1364-
if (ch == EOF) {
1365-
if (spaces < _state.Indent[_state.IndentLevel]) {
1366-
if (_sourceUnit.Kind == SourceCodeKind.InteractiveCode ||
1367-
_sourceUnit.Kind == SourceCodeKind.Statements) {
1368-
SetIndent(spaces, null);
1369-
} else {
1370-
DoDedent(spaces, _state.Indent[_state.IndentLevel]);
1371-
}
1372-
}
1373-
} else if (ch != '\n' && ch != '\r') {
1374-
SetIndent(spaces, null);
1375-
}
1376-
1377-
return true;
1378-
}
1379-
}
1380-
}
1381-
1382-
// This is another version of ReadNewline with nearly identical semantics. The difference is
1383-
// that checks are made to see that indentation is used consistently. This logic is in a
1384-
// duplicate method to avoid inflicting the overhead of the extra logic when we're not making
1385-
// the checks.
1386-
private bool ReadNewlineWithChecks() {
1387-
// Keep track of the indentation format for the current line
1316+
// Keep track of the indentation format for the current line - may want to optimize in the future
13881317
StringBuilder sb = new StringBuilder(80);
13891318

13901319
int spaces = 0;
@@ -1394,7 +1323,7 @@ private bool ReadNewlineWithChecks() {
13941323
switch (ch) {
13951324
case ' ': spaces += 1; sb.Append(' '); break;
13961325
case '\t': spaces += 8 - (spaces % 8); sb.Append('\t'); break;
1397-
case '\f': spaces = 0; sb.Append('\f'); break;
1326+
case '\f': spaces = 0; break;
13981327

13991328
case '#':
14001329
if (_verbatim) {
@@ -1463,24 +1392,21 @@ private void CheckIndent(StringBuilder sb) {
14631392
// We've hit a difference in the way we're indenting, report it.
14641393
_errors.Add(_sourceUnit, Resources.InconsistentWhitespace,
14651394
new SourceSpan(eoln_token_end, eoln_token_end), // TODO: we can report better span - starting at the beginning of the line
1466-
ErrorCodes.TabError, _indentationInconsistencySeverity
1395+
ErrorCodes.TabError, Severity.Error
14671396
);
1468-
1469-
// We only report problems once per module, so switch back to the fast algorithm.
1470-
_indentationInconsistencySeverity = Severity.Ignore;
14711397
}
14721398
}
14731399
}
14741400
}
14751401

1402+
14761403
private void SetIndent(int spaces, StringBuilder chars) {
14771404
int current = _state.Indent[_state.IndentLevel];
14781405
if (spaces == current) {
14791406
return;
14801407
} else if (spaces > current) {
14811408
_state.Indent[++_state.IndentLevel] = spaces;
1482-
if (_state.IndentFormat != null)
1483-
_state.IndentFormat[_state.IndentLevel] = chars;
1409+
_state.IndentFormat[_state.IndentLevel] = chars;
14841410
_state.PendingDedents = -1;
14851411
return;
14861412
} else {
@@ -1656,8 +1582,6 @@ private struct State : IEquatable<State> {
16561582
public int PendingDedents;
16571583
public bool LastNewLine; // true if the last token we emitted was a new line.
16581584
public IncompleteString IncompleteString;
1659-
1660-
// Indentation state used only when we're reporting on inconsistent identation format.
16611585
public StringBuilder[] IndentFormat;
16621586

16631587
// grouping state
@@ -1671,15 +1595,15 @@ public State(State state) {
16711595
BraceLevel = state.BraceLevel;
16721596
PendingDedents = state.PendingDedents;
16731597
IndentLevel = state.IndentLevel;
1674-
IndentFormat = (state.IndentFormat != null) ? (StringBuilder[])state.IndentFormat.Clone() : null;
1598+
IndentFormat = (StringBuilder[])state.IndentFormat.Clone();
16751599
IncompleteString = state.IncompleteString;
16761600
}
16771601

16781602
public State(object dummy) {
16791603
Indent = new int[MaxIndent]; // TODO
16801604
LastNewLine = false;
16811605
BracketLevel = ParenLevel = BraceLevel = PendingDedents = IndentLevel = 0;
1682-
IndentFormat = null;
1606+
IndentFormat = new StringBuilder[MaxIndent];
16831607
IncompleteString = null;
16841608
}
16851609

Src/IronPython/Hosting/PythonOptionsParser.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,13 @@ protected override void ParseArgument(string/*!*/ arg) {
9090
LanguageSetup.Options["IgnoreEnvironment"] = ScriptingRuntimeHelpers.True;
9191
break;
9292

93-
case "-t": LanguageSetup.Options["IndentationInconsistencySeverity"] = Severity.Warning; break;
94-
case "-tt": LanguageSetup.Options["IndentationInconsistencySeverity"] = Severity.Error; break;
93+
case "-t":
94+
//ignore for backwards compatibility
95+
break;
96+
97+
case "-tt":
98+
//ignore for backwards compatibility
99+
break;
95100

96101
case "-O":
97102
LanguageSetup.Options["Optimize"] = ScriptingRuntimeHelpers.True;
@@ -257,8 +262,6 @@ public override void GetHelp(out string commandLine, out string[,] options, out
257262
{ "-S", "Don't imply 'import site' on initialization" },
258263
{ "-s", "Don't add user site directory to sys.path" },
259264
{ "-I", "isolate IronPython from the user's environment (implies -E and -s)" },
260-
{ "-t", "Issue warnings about inconsistent tab usage" },
261-
{ "-tt", "Issue errors for inconsistent tab usage" },
262265
{ "-W arg", "Warning control (arg is action:message:category:module:lineno) also IRONPYTHONWARNINGS=arg" },
263266
{ "-q", "don't print version and copyright messages on interactive startup" },
264267

Src/IronPython/Modules/sys.cs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ public static int getrecursionlimit(CodeContext/*!*/ context) {
302302

303303
[PythonHidden, PythonType("flags"), DontMapIEnumerableToIter]
304304
public sealed class SysFlags : PythonTuple {
305-
internal SysFlags() : base(new object[n_fields] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }) { }
305+
internal SysFlags() : base(new object[n_fields] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }) { }
306306

307307
private const int INDEX_DEBUG = 0;
308308
private const int INDEX_INSPECT = 1;
@@ -312,14 +312,13 @@ internal SysFlags() : base(new object[n_fields] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
312312
private const int INDEX_NO_USER_SITE = 5;
313313
private const int INDEX_NO_SITE = 6;
314314
private const int INDEX_IGNORE_ENVIRONMENT = 7;
315-
private const int INDEX_TABCHECK = 8;
316-
private const int INDEX_VERBOSE = 9;
317-
private const int INDEX_UNICODE = 10;
318-
private const int INDEX_BYTES_WARNING = 11;
319-
private const int INDEX_QUIET = 12;
320-
321-
public const int n_fields = 13;
322-
public const int n_sequence_fields = 13;
315+
private const int INDEX_VERBOSE = 8;
316+
private const int INDEX_UNICODE = 9;
317+
private const int INDEX_BYTES_WARNING = 10;
318+
private const int INDEX_QUIET = 11;
319+
320+
public const int n_fields = 12;
321+
public const int n_sequence_fields = 12;
323322
public const int n_unnamed_fields = 0;
324323

325324
public override string __repr__(CodeContext context) {
@@ -332,7 +331,6 @@ public override string __repr__(CodeContext context) {
332331
$"{nameof(no_user_site)}={no_user_site}",
333332
$"{nameof(no_site)}={no_site}",
334333
$"{nameof(ignore_environment)}={ignore_environment}",
335-
$"{nameof(tabcheck)}={tabcheck}",
336334
$"{nameof(verbose)}={verbose}",
337335
$"{nameof(unicode)}={unicode}",
338336
$"{nameof(bytes_warning)}={bytes_warning}",
@@ -383,11 +381,6 @@ public int ignore_environment {
383381
internal set => _data[INDEX_IGNORE_ENVIRONMENT] = value;
384382
}
385383

386-
public int tabcheck {
387-
get => (int)_data[INDEX_TABCHECK];
388-
internal set => _data[INDEX_TABCHECK] = value;
389-
}
390-
391384
public int verbose {
392385
get => (int)_data[INDEX_VERBOSE];
393386
internal set => _data[INDEX_VERBOSE] = value;

Src/IronPython/Runtime/PythonContext.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -719,14 +719,6 @@ private void InitializeSysFlags() {
719719
flags.no_user_site = PythonOptions.NoUserSite ? 1 : 0;
720720
flags.no_site = PythonOptions.NoSite ? 1 : 0;
721721
flags.ignore_environment = PythonOptions.IgnoreEnvironment ? 1 : 0;
722-
switch (PythonOptions.IndentationInconsistencySeverity) {
723-
case Severity.Warning:
724-
flags.tabcheck = 1;
725-
break;
726-
case Severity.Error:
727-
flags.tabcheck = 2;
728-
break;
729-
}
730722
flags.verbose = PythonOptions.Verbose ? 1 : 0;
731723
flags.unicode = 1;
732724
flags.bytes_warning = PythonOptions.BytesWarning switch {

Src/IronPython/Runtime/PythonOptions.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,6 @@ public sealed class PythonOptions : LanguageOptions {
9696
/// </summary>
9797
public bool Tracing { get; }
9898

99-
/// <summary>
100-
/// Severity of a warning that indentation is formatted inconsistently.
101-
/// </summary>
102-
public Severity IndentationInconsistencySeverity { get; }
103-
10499
/// <summary>
105100
/// Forces all code to be compiled in a mode in which the code can be reliably collected by the CLR.
106101
/// </summary>
@@ -142,7 +137,6 @@ public PythonOptions(IDictionary<string, object> options)
142137
Optimize = GetOption(options, "Optimize", false);
143138
StripDocStrings = GetOption(options, "StripDocStrings", false);
144139
RecursionLimit = GetOption(options, "RecursionLimit", Int32.MaxValue);
145-
IndentationInconsistencySeverity = GetOption(options, "IndentationInconsistencySeverity", Severity.Ignore);
146140
EnableProfiler = GetOption(options, "EnableProfiler", false);
147141
LightweightScopes = GetOption(options, "LightweightScopes", false);
148142
FullFrames = GetOption(options, "FullFrames", false);

Src/IronPythonTest/EngineTest.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ public void ScenarioHostingHelpers() {
216216
options["StripDocStrings"] = true;
217217
options["Optimize"] = true;
218218
options["RecursionLimit"] = 42;
219-
options["IndentationInconsistencySeverity"] = Severity.Warning;
220219
options["WarningFilters"] = new string[] { "warnonme" };
221220

222221
ScriptEngine engine1 = Python.CreateEngine();
@@ -276,7 +275,6 @@ private void TestEngine(ScriptEngine scriptEngine, Dictionary<string, object> op
276275
Assert.AreEqual(po.StripDocStrings, true);
277276
Assert.AreEqual(po.Optimize, true);
278277
Assert.AreEqual(po.RecursionLimit, 42);
279-
Assert.AreEqual(po.IndentationInconsistencySeverity, Severity.Warning);
280278
Assert.AreEqual(po.WarningFilters[0], "warnonme");
281279
}
282280

Tests/test_regressions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -589,13 +589,13 @@ def cp22692_helper(self, source, flags):
589589

590590
def test_cp22692(self):
591591
self.assertEqual(self.cp22692_helper("if 1:", 0x200),
592-
[SyntaxError, IndentationError if is_cli else SyntaxError])
592+
[IndentationError if sys.version_info >= (3,9) else SyntaxError, IndentationError if sys.version_info >= (3,9) else SyntaxError])
593593
self.assertEqual(self.cp22692_helper("if 1:", 0),
594-
[SyntaxError, IndentationError if is_cli else SyntaxError])
594+
[IndentationError if sys.version_info >= (3,9) else SyntaxError, IndentationError if sys.version_info >= (3,9) else SyntaxError])
595595
self.assertEqual(self.cp22692_helper("if 1:\n if 1:", 0x200),
596-
[IndentationError if is_cli else SyntaxError, IndentationError if is_cli else SyntaxError])
596+
[IndentationError if is_cli or sys.version_info >= (3,9) else SyntaxError, IndentationError if is_cli or sys.version_info >= (3,9) else SyntaxError])
597597
self.assertEqual(self.cp22692_helper("if 1:\n if 1:", 0),
598-
[IndentationError if is_cli else SyntaxError, IndentationError if is_cli else SyntaxError])
598+
[IndentationError if is_cli or sys.version_info >= (3,9) else SyntaxError, IndentationError if is_cli or sys.version_info >= (3,9) else SyntaxError])
599599

600600
@skipUnlessIronPython()
601601
def test_cp23545(self):

Tests/test_stdconsole.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,8 @@ def test_t(self):
229229
f.write("if (1):\n\tpass\n pass\nprint('OK')\n")
230230

231231
msg = "inconsistent use of tabs and spaces in indentation"
232-
if is_cli: # https://github.com/IronLanguages/ironpython3/issues/982
233-
self.TestCommandLine((tmpscript, ), "OK\n")
234-
self.TestCommandLine(("-t", tmpscript), ("firstline", "%s:3: SyntaxWarning: %s\n" % (tmpscript, msg, )), 0)
235-
else:
236-
self.TestCommandLine((tmpscript, ), ("lastline", "TabError: " + msg + "\n"), 1)
237-
self.TestCommandLine(("-t", tmpscript), ("lastline", "TabError: " + msg + "\n"), 1)
232+
self.TestCommandLine((tmpscript, ), ("lastline", "TabError: " + msg + "\n"), 1)
233+
self.TestCommandLine(("-t", tmpscript), ("lastline", "TabError: " + msg + "\n"), 1)
238234
self.TestCommandLine(("-tt", tmpscript), ("lastline", "TabError: " + msg + "\n"), 1)
239235

240236
tmpscript = os.path.join(self.tmpdir, "funcdef.py")

0 commit comments

Comments
 (0)