[Python-ideas] Runtime assertion with no overhead when not active
Eloi.Gaudry at fft.be
Tue May 8 11:51:12 EDT 2018
On Wed, 2018-05-09 at 01:34 +1000, Steven D'Aprano wrote:
> On Tue, May 08, 2018 at 07:37:55AM +0000, Eloi Gaudry wrote:
> > * debug assert, for helping developing a new features, used with
> > debug-
> > builds
> > * runtime assert, for ensuring correctness and/or diagnosing issue
> > with
> > production/release-builds on-site.
> I don't think that is a useful distinction to make.
> I use `assert` all the time, and I have never once cared whether it
> is a
> "debug build" or a "production build". I use assert in my code, and
> people (including me) can use it with whatever build of Python they
I do understand your point but I don't share your opinion.
I think that is a difference between:
- the current 'assert' which usage seems (to me) to focus on
development correctness (I think of it as the C-assert enabled in any C
program in debug build )
- the runtime_assert that I submitted on the list, which would be
focusing on usage correctness (hence runtime), and easily disabled at
runtime (when the python command line options parsing is not an option,
for instance when the python interpreter is not python itself and/or
when the consumer/extension wants to behave differently).
> I don't even know which builds of Python I'm running. My *guess* is
> the OS-provided Python is probably a non-debug build, and the ones
> compiled from source will be whatever the default build settings
> but I don't know what that is or how to find out.
> And if there was some sort of runtime_assert that could be enabled
> disabled individually, why wouldn't I use it with debug builds as
> as non-debug builds?
There would be no reason why, but you would benefit from being able to
easily activate/deactivate the runtime assert.
More information about the Python-ideas