diff options
author | Peter Donis <peterdonis@alum.mit.edu> | 2021-03-02 17:06:20 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-02 17:06:20 (GMT) |
commit | b36349a647b2bf8174f0e736a4fc347e92ae204e (patch) | |
tree | 1093c4e0351e7924a0088ffc04bcf2b73d59d809 | |
parent | 503627fc2acb875b4c7b58a7f6e258cfcbad054b (diff) | |
download | cpython-b36349a647b2bf8174f0e736a4fc347e92ae204e.zip cpython-b36349a647b2bf8174f0e736a4fc347e92ae204e.tar.gz cpython-b36349a647b2bf8174f0e736a4fc347e92ae204e.tar.bz2 |
bpo-43049: Use io.IncrementalNewlineDecoder for doctest newline conversion (GH-24359)
Followup to bpo-1812 and GH-17385.
-rw-r--r-- | Lib/doctest.py | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/Lib/doctest.py b/Lib/doctest.py index 5bb35c9..e95c333 100644 --- a/Lib/doctest.py +++ b/Lib/doctest.py @@ -102,7 +102,7 @@ import re import sys import traceback import unittest -from io import StringIO +from io import StringIO, IncrementalNewlineDecoder from collections import namedtuple TestResults = namedtuple('TestResults', 'failed attempted') @@ -212,11 +212,8 @@ def _normalize_module(module, depth=2): raise TypeError("Expected a module, string, or None") def _newline_convert(data): - # We have two cases to cover and we need to make sure we do - # them in the right order - for newline in ('\r\n', '\r'): - data = data.replace(newline, '\n') - return data + # The IO module provides a handy decoder for universal newline conversion + return IncrementalNewlineDecoder(None, True).decode(data, True) def _load_testfile(filename, package, module_relative, encoding): if module_relative: |