[New-bugs-announce] [issue18682] [PATCH] remove bogus codepath from pprint._safe_repr

Michal Vyskocil report at bugs.python.org
Thu Aug 8 10:29:26 CEST 2013

New submission from Michal Vyskocil:

pprint._safe_repr for type str uses much slower codepath by default, which does not makes a sense in Python3 context. Instead of simply using repr, it check the existence of 'locale' in sys.modules and if found, it goes one-by-one-char call str.isalpha() on each and apply the quoting for non-alpha chars. This is extremely slow, but as locale is usually in sys.modules, it's used by default.

The point of such code was because in python2, str.isalpha() depends on locale, so for locale-aware Python builds, there was a different path needed. But this does not apply for Python3, where all strings are unicode, so .isaplha() is not locale sensitive anymore.

components: Library (Lib)
files: pprint-remove-bogus-code.patch
keywords: patch
messages: 194652
nosy: mvyskocil
priority: normal
severity: normal
status: open
title: [PATCH] remove bogus codepath from pprint._safe_repr
type: performance
Added file: http://bugs.python.org/file31193/pprint-remove-bogus-code.patch

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list