Skip to content
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

Design Guide Update - Exception and asserts #4185

Merged
merged 1 commit into from
Feb 12, 2021
Merged
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
18 changes: 18 additions & 0 deletions docs/design_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,24 @@ use what.
Here is more info on properties from
`Python <https://docs.python.org/3/library/functions.html#property>`_.

Exceptions and asserts
--------------------------------------------------------------------------------

Raise an appropriate `Exception <https://docs.python.org/3/library/exceptions.html#bltin-exceptions>`_,
along with a useful message, whenever a critical test or other condition fails.

Example::

if not 0 <= pin <= 7:
raise ValueError("Pin number must be 0-7.")

If memory is constrained and a more compact method is needed, use `assert`
instead.

Example::

assert 0 <= pin <= 7, "Pin number must be 0-7."

Design for compatibility with CPython
--------------------------------------------------------------------------------

Expand Down