[Python-Dev] Add a developer mode to Python: -X dev command line option

Victor Stinner victor.stinner at gmail.com
Mon Nov 13 12:19:07 EST 2017

2017-11-13 17:51 GMT+01:00 Antoine Pitrou <antoine at python.org>:
> The main issue I have with `-b` is actually that you can get spurious
> warnings about properly working code.  You can also get warnings in
> well-tested third-party libraries, e.g.:
> distributed/tests/test_client.py::test_get_versions
>   /home/antoine/miniconda3/envs/dask36/lib/python3.6/site-packages/pandas/core/dtypes/common.py:20: BytesWarning: Comparison between bytes and string
>     for t in ['O', 'int8', 'uint8', 'int16', 'uint16',
>   /home/antoine/miniconda3/envs/dask36/lib/python3.6/site-packages/pandas/io/packers.py:231: BytesWarning: Comparison between bytes and string
>     7: np.dtype('int64'),

Oh right, that's a very good reason to not include -b option in the -X
dev mode ;-)

Usually, I mostly care of ResourceWarning and DeprecationWarning warnings.

PYTHONMALLOC=debug and -X faulthandler just comes "for free", they
don't change the behaviour as -b, and should help to debug crashes.


By the way, My worst memory of BytesWarning is when implemented/fixed
(I don't call) os.get_exec_path():

    # {b'PATH': ...}.get('PATH') and {'PATH': ...}.get(b'PATH') emit a
    # BytesWarning when using python -b or python -bb: ignore the warning
    with warnings.catch_warnings():
        warnings.simplefilter("ignore", BytesWarning)

I really dislike this code since warnings.catch_warnings() is
process-wide and so impact other threads :-(

(Maybe Yury's PEP "context variables" would help here? ;-))


More information about the Python-Dev mailing list