First off, I don't intend for this to be an answer since I don't think it is one. This was too big for a comment and there are a few things that I want to chip in to this post.
There are a couple reasons that it would check locale. The primary reason to be aware of, I believe, is that character encoding of the string is heavily dependent on the locale. The second thing is that when locale
object is present, that can coerce the locale to format a string in a manner which is not consistent with what the pprint
object method would like.
Another thing, I found, is that when running on a windows system. If I do the following:
>>> import sys
>>> 'locale' in sys.modules
True
However, when I run the same test on my GoDaddy shell account:
>>> import sys
>>> 'locale' in sys.modules
False
So, this could be a method to, among other things, quickly check what kind of operating system the user is running on, and then act accordingly.
Also, interestingly enough, I performed the following test on both a Linux system and on a Windows system:
>>>import locale
>>>locale.getdefaultlocale()
The Linux system returned:
(None, None)
The Windows system returned:
('en_US', 'cp1252')
So, what I think is happening is that some of these characters might have a different kind of encoding and change the output of what we want repr() to show us. These locale-dependent effects on character encodings and alterations to strings, I think, would coerce a non-homogeneous output.