Opened 3 years ago

Last modified 3 years ago

#23504 new enhancement

Fast assertions — at Version 1

Reported by: roed Owned by:
Priority: major Milestone: sage-8.1
Component: misc Keywords: sd87
Cc: saraedum Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description (last modified by saraedum)

It would be cool to have an assertion that was possible to turn on and off, and that weren't caught by except Exception. For example:

class Assertion_Error(BaseException):
def assert_(F, msg=None, args=(), kwds={}):
    if not callable(F):
        raise ValueError("Must use a callable")
    if assertions_enabled and not F(*args, **kwds):
        raise Assertion_Error(msg)

One could probably also have msg be lazy as well...

Change History (1)

comment:1 Changed 3 years ago by saraedum

  • Description modified (diff)
Note: See TracTickets for help on using tickets.