Skip to content

Commit 9062f02

Browse files
authored
Fix StringIO newline splitting and character positions (#8351)
* Keep StringIO text operations CPython-compatible Constraint: email.feedparser depends on StringIO(newline='') recognizing CR, LF, and CRLF boundaries. Rejected: an email-specific parser workaround | StringIO is the shared root cause. Confidence: high Scope-risk: moderate Directive: Keep internal storage byte-based; convert only at StringIO API boundaries. Tested: prek run --all-files; test_memoryio; test_email; full workspace verification by contributor Assisted-by: Codex:gpt-5.6-sol * Run restored StringIO conformance tests Constraint: upstream StringIO tests already cover the repaired behavior. Rejected: new RustPython-only regression tests | existing CPython coverage is sufficient. Confidence: high Scope-risk: narrow Directive: Remove expected-failure markers only while the inherited tests pass. Tested: prek run --all-files; test_memoryio; test_email Assisted-by: Codex:gpt-5.6-sol * Keep StringIO newline handling consistent Constraint: StringIO must apply its newline mode consistently when constructing, writing, and reading text.\nRejected: a readline-only fix | it leaves CR and CRLF modes internally inconsistent.\nConfidence: high\nScope-risk: moderate\nDirective: Keep StringIO buffer contents valid WTF-8 before using unchecked views.\nTested: prek run --all-files; cargo clippy -p rustpython-vm -- -D warnings; test_memoryio; test_shlex; test_email; workspace excluding rustpython-capi; full workspace manually verified by contributor\nNot-tested: local rustpython-capi workspace test crashes with a pre-existing macOS SIGSEGV\nAssisted-by: Codex:gpt-5.6-sol
1 parent c6b80e8 commit 9062f02

4 files changed

Lines changed: 121 additions & 88 deletions

File tree

‎Lib/test/test_email/test_email.py‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3812,7 +3812,6 @@ def test_typed_subpart_iterator_default_type(self):
38123812
-Me
38133813
""")
38143814

3815-
@unittest.expectedFailure # TODO: RUSTPYTHON
38163815
def test_pushCR_LF(self):
38173816
'''FeedParser BufferedSubFile.push() assumed it received complete
38183817
line endings. A CR ending one push() followed by a LF starting
@@ -3843,7 +3842,6 @@ def test_pushCR_LF(self):
38433842
self.assertEqual(len(om), nt)
38443843
self.assertEqual(''.join([il for il, n in imt]), ''.join(om))
38453844

3846-
@unittest.expectedFailure # TODO: RUSTPYTHON
38473845
def test_push_random(self):
38483846
from email.feedparser import BufferedSubFile, NeedMoreData
38493847

@@ -3877,7 +3875,6 @@ def test_empty_header_name_handled(self):
38773875
self.assertEqual(msg['First'], 'val')
38783876
self.assertEqual(msg['Second'], 'val')
38793877

3880-
@unittest.expectedFailure # TODO: RUSTPYTHON; Feedparser.feed -> Feedparser._input.push, Feedparser._call_parse -> Feedparser._parse does not keep _input state between calls
38813878
def test_newlines(self):
38823879
m = self.parse(['a:\nb:\rc:\r\nd:\n'])
38833880
self.assertEqual(m.keys(), ['a', 'b', 'c', 'd'])
@@ -3896,7 +3893,6 @@ def test_newlines(self):
38963893
m = self.parse(['a:\r', 'b:\x85', 'c:\n'])
38973894
self.assertEqual(m.items(), [('a', ''), ('b', '\x85c:')])
38983895

3899-
@unittest.expectedFailure # TODO: RUSTPYTHON
39003896
def test_long_lines(self):
39013897
# Expected peak memory use on 32-bit platform: 6*N*M bytes.
39023898
M, N = 1000, 20000

‎Lib/test/test_memoryio.py‎

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,6 @@ class CStringIOTest(PyStringIOTest):
940940

941941
# XXX: For the Python version of io.StringIO, this is highly
942942
# dependent on the encoding used for the underlying buffer.
943-
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: 8 != 2
944943
def test_widechar(self):
945944
buf = self.buftype("\U0002030a\U00020347")
946945
memio = self.ioclass(buf)
@@ -965,7 +964,6 @@ def test_getstate(self):
965964
memio.close()
966965
self.assertRaises(ValueError, memio.__getstate__)
967966

968-
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: ValueError not raised by __setstate__
969967
def test_setstate(self):
970968
# This checks whether __setstate__ does proper input validation.
971969
memio = self.ioclass()
@@ -1002,22 +1000,6 @@ def __str__(self):
10021000
memio2.write(MyStr("world"))
10031001
self.assertEqual(memio2.getvalue(), "hello world")
10041002

1005-
@unittest.expectedFailure # TODO: RUSTPYTHON; +
1006-
def test_issue5265(self):
1007-
return super().test_issue5265()
1008-
1009-
@unittest.expectedFailure # TODO: RUSTPYTHON; ? ++++
1010-
def test_newline_empty(self):
1011-
return super().test_newline_empty()
1012-
1013-
@unittest.expectedFailure # TODO: RUSTPYTHON; ? ^^^^^
1014-
def test_newline_none(self):
1015-
return super().test_newline_none()
1016-
1017-
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: OSError not raised by seek
1018-
def test_relative_seek(self):
1019-
return super().test_relative_seek()
1020-
10211003
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: ValueError not raised by writable
10221004
def test_flags(self):
10231005
return super().test_flags()
@@ -1026,15 +1008,6 @@ def test_flags(self):
10261008
def test_newlines_property(self):
10271009
return super().test_newlines_property()
10281010

1029-
@unittest.expectedFailure # TODO: RUSTPYTHON; d
1030-
def test_newline_cr(self):
1031-
return super().test_newline_cr()
1032-
1033-
@unittest.expectedFailure # TODO: RUSTPYTHON; d
1034-
def test_newline_crlf(self):
1035-
return super().test_newline_crlf()
1036-
1037-
10381011
class CStringIOPickleTest(PyStringIOPickleTest):
10391012
UnsupportedOperation = io.UnsupportedOperation
10401013

@@ -1044,34 +1017,9 @@ def __new__(cls, *args, **kwargs):
10441017
def __init__(self, *args, **kwargs):
10451018
pass
10461019

1047-
@unittest.expectedFailure # TODO: RUSTPYTHON; +
1048-
def test_issue5265(self):
1049-
return super().test_issue5265()
1050-
1051-
@unittest.expectedFailure # TODO: RUSTPYTHON; ? ++++
1052-
def test_newline_empty(self):
1053-
return super().test_newline_empty()
1054-
1055-
@unittest.expectedFailure # TODO: RUSTPYTHON; ? ^^^^^
1056-
def test_newline_none(self):
1057-
return super().test_newline_none()
1058-
1059-
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: OSError not raised by seek
1060-
def test_relative_seek(self):
1061-
return super().test_relative_seek()
1062-
10631020
@unittest.expectedFailure # TODO: RUSTPYTHON; AttributeError: 'StringIO' object has no attribute 'newlines'. Did you mean: 'readlines'?
10641021
def test_newlines_property(self):
10651022
return super().test_newlines_property()
10661023

1067-
@unittest.expectedFailure # TODO: RUSTPYTHON; d
1068-
def test_newline_cr(self):
1069-
return super().test_newline_cr()
1070-
1071-
@unittest.expectedFailure # TODO: RUSTPYTHON; d
1072-
def test_newline_crlf(self):
1073-
return super().test_newline_crlf()
1074-
1075-
10761024
if __name__ == '__main__':
10771025
unittest.main()

‎Lib/test/test_shlex.py‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,10 @@ def testSplitNone(self):
167167
with self.assertRaises(ValueError):
168168
shlex.split(None)
169169

170-
@unittest.expectedFailure # TODO: RUSTPYTHON; ValueError: Error Retrieving Value
171170
def testSplitPosix(self):
172171
"""Test data splitting with posix parser"""
173172
self.splitTest(self.posix_data, comments=True)
174173

175-
@unittest.expectedFailure # TODO: RUSTPYTHON; ValueError: Error Retrieving Value
176174
def testCompat(self):
177175
"""Test compatibility interface"""
178176
for i in range(len(self.data)):
@@ -313,7 +311,6 @@ def testEmptyStringHandling(self):
313311
s = shlex.shlex("'')abc", punctuation_chars=True)
314312
self.assertEqual(list(s), expected)
315313

316-
@unittest.expectedFailure # TODO: RUSTPYTHON; ValueError: Error Retrieving Value
317314
def testUnicodeHandling(self):
318315
"""Test punctuation_chars and whitespace_split handle unicode."""
319316
ss = "\u2119\u01b4\u2602\u210c\u00f8\u1f24"
@@ -356,7 +353,6 @@ def testJoin(self):
356353
joined = shlex.join(split_command)
357354
self.assertEqual(joined, command)
358355

359-
@unittest.expectedFailure # TODO: RUSTPYTHON; ValueError: Error Retrieving Value
360356
def testJoinRoundtrip(self):
361357
all_data = self.data + self.posix_data
362358
for command, *split_command in all_data:

0 commit comments

Comments
 (0)