[Python-ideas] Runtime assertion with no overhead when not active

Eric V. Smith eric at trueblade.com
Tue May 8 09:58:51 EDT 2018

On 5/8/2018 9:50 AM, Eloi Gaudry wrote:
> On Tue, 2018-05-08 at 09:35 -0400, Eric V. Smith wrote:
>> On 5/8/2018 3:37 AM, Eloi Gaudry wrote:
>>> On Mon, 2018-05-07 at 16:56 +0000, Brett Cannon wrote:
>>>> My question is how is this different to running with -O which
>>>> leaves
>>>> the assert statement out of the bytecode and so you avoid any
>>>> run-
>>>> time cost of the statement entirely?
>>> Not so much different, except that:
>>> - the switch won't need to be on the command line
>> So, is the switch set in code? If so, what would that look like?
>> Eric
> So far, I only have the "extension" method, where a global variable is
> set directly from within the C-interface, as currently done with the
> debug assert:
> Include/pydebug.h : int Py_RuntimeAssertFlag = 1;
> Your_extension/main.c : SetFlag(Py_RuntimeAssertFlag);

I think what's confusing to me (and maybe others) is that we haven't 
seen your vision on how this would look in Python code.

An example that would throw runtime assertions and the same example 
where it wouldn't (after a global switch is set?) would be helpful.


More information about the Python-ideas mailing list