[Python-ideas] Runtime assertion with no overhead when not active
steve at pearwood.info
Wed May 16 13:09:31 EDT 2018
On Wed, May 16, 2018 at 01:27:50PM +0000, Eloi Gaudry wrote:
> On Wed, 2018-05-16 at 21:15 +1000, Steven D'Aprano wrote:
> > On Wed, May 16, 2018 at 08:29:00AM +0000, Eloi Gaudry wrote:
> > > Is there some interest in the proposal or should I finally close
> > > this
> > > thread ?
> > I'm definitely interested in the concept, not the suggested syntax
> > or semantics.
> Would you briefly describe a syntax that would better fit this concept
The syntax is the minor point: you give is an ungainly name,
"runtime_assert", and your proposed PEP shows it requiring parentheses
as if it were an ordinary function.
The bigger problem is the semantics. As I already said in an earlier
email, you don't explain what "runtime_assert_active" is (is it a
per-module global variable? a single application-wide super-global? a
local variable? something else?) or how we are supposed to set it. That
too is an ungainly name, and the fact that there's only *one* such flag
(whether it is per module or not) makes this proposal useless for my
Another problem is that your runtime_assert *prints* the error
message instead of raising an exception, and there's no way to
customise the message.
But the most important reason is that I'm not really interested in
adding a new keyword for this. I would much prefer to explore ways to
allow ordinary functions to receive arguments and be able to delay
evaluation of those arguments until needed.
More information about the Python-ideas