Skip to content

Commit b36349a

Browse files
authored
bpo-43049: Use io.IncrementalNewlineDecoder for doctest newline conversion (GH-24359)
Followup to bpo-1812 and GH-17385.
1 parent 503627f commit b36349a

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

Lib/doctest.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def _test():
102102
import sys
103103
import traceback
104104
import unittest
105-
from io import StringIO
105+
from io import StringIO, IncrementalNewlineDecoder
106106
from collections import namedtuple
107107

108108
TestResults = namedtuple('TestResults', 'failed attempted')
@@ -212,11 +212,8 @@ def _normalize_module(module, depth=2):
212212
raise TypeError("Expected a module, string, or None")
213213

214214
def _newline_convert(data):
215-
# We have two cases to cover and we need to make sure we do
216-
# them in the right order
217-
for newline in ('\r\n', '\r'):
218-
data = data.replace(newline, '\n')
219-
return data
215+
# The IO module provides a handy decoder for universal newline conversion
216+
return IncrementalNewlineDecoder(None, True).decode(data, True)
220217

221218
def _load_testfile(filename, package, module_relative, encoding):
222219
if module_relative:

0 commit comments

Comments
 (0)