This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author barry
Recipients barry
Date 2016-04-06.14:43:36
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1459953817.06.0.108745447257.issue26702@psf.upfronthosting.co.za>
In-reply-to
Content
Too many times I hit failing assert statements, and have no idea what value is causing the assertion to fail.  Sure, you can provide a value to print (instead of just the failing code) but it seems to be fairly rarely used.  And it can also lead to code duplication.  As an example, I saw this today in some installed code:

assert k.replace('.', '').replace('-', '').replace('_', '').isalum()

So now I have to sudo edit the installed system file, duplicate everything up to but not including the .isalum() as the second argument to assert, then try to reproduce the problem.  IWBNI assert could make this better.

One idea would be to split the value and the conditional being asserted on that value, but we can't use two-argument asserts for that.  Crazy syntax thought: reuse the 'with' keyword:

assert k.replace('.', '').replace('-', '').replace('_', '') with isalum

where the part before the 'with' is 'value' and the part after the 'with' is conditional, and the two parts together imply the expression.

This would be equivalent to:

if __debug__:
    if not value.conditional():
        raise AssertionError(expression, value, conditional)

I suppose you then want to support arguments:

assert foo with can_bar, 1, 2, x=3

but maybe that's YAGNI and we can just say to use a better 2-value assert in those more complicated cases.
History
Date User Action Args
2016-04-06 14:43:37barrysetrecipients: + barry
2016-04-06 14:43:37barrysetmessageid: <1459953817.06.0.108745447257.issue26702@psf.upfronthosting.co.za>
2016-04-06 14:43:37barrylinkissue26702 messages
2016-04-06 14:43:36barrycreate