[Python-Dev] r84204 - in python/branches/py3k/Lib: os.py test/test_os.py

Antoine Pitrou solipsis at pitrou.net
Thu Aug 19 19:15:15 CEST 2010


On Thu, 19 Aug 2010 19:10:19 +0200 (CEST)
victor.stinner <python-checkins at python.org> wrote:
> Author: victor.stinner
> Date: Thu Aug 19 19:10:18 2010
> New Revision: 84204
> 
> Log:
> Fix os.get_exec_path() (code and tests) for python -bb
> 
> Catch BytesWarning exceptions.

You should not catch warnings, but silence them using constructs
provided by the warnings module:

    with warnings.catch_warnings():
        warnings.simplefilter(ignore, BytesWarning)
        # the rest of your code


Otherwise you'll get buggy behaviour where e.g. env[b'PATH'] raises
BytesWarning because of an unicode key, but it would have succeeded
otherwise.

Regards

Antoine.




More information about the Python-Dev mailing list