Skip to content

bpo-43049: Use io.IncrementalNewlineDecoder for doctest newline conversion #24359

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions Lib/doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def _test():
import sys
import traceback
import unittest
from io import StringIO
from io import StringIO, IncrementalNewlineDecoder
from collections import namedtuple

TestResults = namedtuple('TestResults', 'failed attempted')
Expand Down Expand Up @@ -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:
Expand Down