Skip to content

PEP : runtime_assert #641

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions pep-9999.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
PEP: 9999
Title: Smart runtime assertion
Author: Eloi Gaudry <eloi.gaudry@fft.be>
Status: Draft
Type: Standards Track
Python-Version: 2.7
Content-Type: text/x-rst
Created: 04-May-2018
Post-History:


Abstract
========

This PEP aims at offering a runtime assert functionnality, extending
the compiletime assert already available.




Rationale
=========

There is no runtime assert relying on python grammar available.
For diagnostics and/or debugging reasons, it would be valuable to
add such a feature.

A runtime assert makes sense when extra checks would be needed
in a production environment (where non-debug builds are used).

By extending the current python grammar, it would be possible to
limit the overhead induces by those runtime asserts when running
in a non "assertive" mode (-ed). The idea here is
to avoid evaluating the expression when runtime assertion is not
active.

A brief example why avoiding evaluating the expression is needed
to avoid any overhead in case the runtime assert should be
ignored.

::
runtime_assert( 999 in { i:None for i in range( 10000000 ) } )

Usage
=====

::
runtime_assert( expr )

#would result in
if expr and runtime_assert_active:
print RuntimeAssertionError()


Implementation details
=====================
There is already an implementation available, robust enough for production.
The implementation is mainly grammar based, and thus the parser and the grammar needs to be updated:
- Python/graminit.c
- Python/ast.c
- Python/symtable.c
- Python/compile.c
- Python/Python-ast.c
- Python/sysmodule.c
- Modules/parsermodule.c
- Include/Python-ast.h
- Include/graminit.h
- Include/pydebug.h
- Grammar/Grammar
- Parser/Python.asdl
- Lib/lib2to3/Grammar.txt
- Lib/compiler/ast.py
- Lib/compiler/pycodegen.py
- Lib/compiler/transformer.py
- Lib/symbol.py
- Modules/parsermodule.c


References
==========

.. [1] PEP 306, How to Change Python's Grammar
(http://www.python.org/dev/peps/pep-0306)


Copyright
=========

This document has been placed in the public domain.



..
Local Variables:
mode: indented-text
indent-tabs-mode: nil
sentence-end-double-space: t
fill-column: 70
coding: utf-8
End: