[Python-Dev] A small patch.

Antoine Pitrou solipsis at pitrou.net
Wed Nov 6 21:43:36 CET 2013


Le 06/11/2013 21:39, Skip Montanaro a écrit :
>> -    assert 1 <= month <= 12, month
>> +    assert 1 <= month <= 12, 'month must be in 1..12'
>
> In addition to Brett's comment, you might as well include the
> offending value in your AssertionError message. For example, a value
> of 0 probably tells you something different about your underlying bug
> than a value of 2013. Just knowing it's out of range isn't really
> enough.

Besides, if it's an assertion it's only an internal helper to check 
implementation correctness. If it's an error that can be caused by 
erroneous user data, it should be replaced with the proper exception 
class (perhaps ValueError).

Regards

Antoine.




More information about the Python-Dev mailing list