[Python-Dev] PEP 538 warning at startup: please remove it

Victor Stinner victor.stinner at gmail.com
Tue Jun 13 05:07:05 EDT 2017

Ok, if you want to have a more concrete example of regression
introduced by this warning, look at test_tracemalloc failures on this
FreeBSD buildbot:

I expect that a *lot* of tests using stderr will be broken by this warning.

I'm not interested to discuss if the CI is properly configured or not.
The thing is the warning can easily be seen as a regression: the test
pass on 3.6 on the same platform ;-)

One example:

FAIL: test_conflicting_envvar_and_command_line
Traceback (most recent call last):
  File "/usr/home/buildbot/python/3.x.koobs-freebsd-current/build/Lib/test/test_warnings/__init__.py",
line 1062, in test_conflicting_envvar_and_command_line
    b"DeprecationWarning: Message"])
AssertionError: Lists differ: [b'Python runtime initialized with
LC_CTYPE=[305 chars]age'] != [b'Traceback (most recent call last):',
b'  [65 chars]age']

First differing element 0:
b'Python runtime initialized with LC_CTYPE=[190 chars]ded.'
b'Traceback (most recent call last):'

First list contains 1 additional elements.
First extra element 3:
b'DeprecationWarning: Message'

- [b'Python runtime initialized with LC_CTYPE=C (a locale with default
ASCII enco'
-  b'ding), which may cause Unicode compatibility problems. Using
C.UTF-8, C.utf8'
-  b', or UTF-8 (if available) as alternative Unicode-compatible
locales is recom'
-  b'mended.',
-  b'Traceback (most recent call last):',
? ^

+ [b'Traceback (most recent call last):',
? ^

   b'  File "<string>", line 1, in <module>',
   b'DeprecationWarning: Message']


2017-06-12 10:56 GMT+02:00 Victor Stinner <victor.stinner at gmail.com>:
> Hi,
> Nick Coghlan pushed his implementation of his PEP 538: nice! Nice step
> forward to UTF-8 everywhere ;-)
> I would prefer to not be annoyed by warning messages about encodings
> at startup if possible:
> "Python detected LC_CTYPE=C: LC_CTYPE coerced to C.UTF-8 (set another
> locale or PYTHONCOERCECLOCALE=0 to disable this locale coercion
> behavior)."
> Python 3.7 is the only programming language that I know that complains
> about encoding at startup. Even if my code is 100% valid, PEP 8
> compliant, don't emit any warning, etc. I will get the warning. It is
> *not* possible to ignore the warning... Like "yeah, I know that my
> locale is C, but it's not like I'm able to configure it."
> haypo at selma$ export LANG=
> haypo at selma$ locale
> ...
> haypo at selma$ ./python -c 'print("Hello World!")' # Python 3.7
> Python detected LC_CTYPE=C: LC_CTYPE coerced to C.UTF-8 (set another
> locale or PYTHONCOERCECLOCALE=0 to disable this locale coercion
> behavior).
> Hello World!
> haypo at selma$ python2 -c 'print("Hello World!")' # Python 2.7
> Hello World!
> haypo at selma$ perl -e 'print "Hello, world!\n"' # Perl 5.24
> Hello, world!
> haypo at selma$ ./c   # C
> Hello World!
> ...
> Note: I don't consider that 2>/dev/null is a good practice to ignore a
> single warning, since it will ignore *all* message written into
> stderr, including useful warnings like ResourceWarning or "Exception
> ignored ...".
> Victor

More information about the Python-Dev mailing list