Opened 6 months ago

Last modified 6 months ago

#23504 new enhancement

Fast assertions

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):
    pass
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 6 months ago by saraedum

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