New submission from STINNER Victor:

Attached patch adds the sys.is_debug_build() public function and replaces 
hasattr(sys, xxx) tests to check for debug mode with sys.is_debug_build().

+.. function:: is_debug_build()
+
+   Return :const:`True` if the Python executable was compiled in debug mode,
+   return :const:`False` if it was compiled in release mode.
+
+   The debug mode is enabled with ``#define Py_DEBUG``, or with
+   ``./configure --with-pydebug``.
+
+   .. versionadded:: 3.6

I would like to add an obvious way to check if Python was compiled in debug 
mode, instead of having hacks/tips to check it.

For example, 3 different checks are proposed on StackOverflow and only one 
looks portable:

http://stackoverflow.com/questions/646518/python-how-to-detect-debug-interpreter

I don't think that we need to mark the function as an implementation detail or 
specific to CPython. Other implementations of Python would probably benefit 
from such flag. If they don't care, they can simply return False.

Alternative: Add a new sys.implementation.debug_build flag.

Note: I chose the "is_debug_build" name using the existing 
sysconfig.is_python_build(). There is a sys.flags.debug flag, so "is_debug()" 
can be confusing. I prefer to attach the "build" suffix.

----------
components: Library (Lib)
files: is_debug_build.patch
keywords: patch
messages: 251765
nosy: haypo
priority: normal
severity: normal
status: open
title: Add sys.is_debug_build() public function to check if Python was compiled 
in debug mode
versions: Python 3.6
Added file: http://bugs.python.org/file40610/is_debug_build.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue25256>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to