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 pgacv2
Recipients paul.j3, pgacv2
Date 2017-05-06.03:02:59
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1494039780.32.0.788090626274.issue30220@psf.upfronthosting.co.za>
In-reply-to
Content
Paul,

There are a number of scenarios in which you need to check a value and not just a type. For instance, I have a tool with several command-line arguments that need to be *nonnegative* integers, and a call to int() would not catch that. Many other utilities that ask for an argument of "how many times do you want to do X?" only make sense if you provide a nonnegative number.

Entering dates is another one. There is no callable in the datetime module or built-in that takes only one argument that can be used to validate a date. And if you write your own, you may need to make sure the date is within a specified range: only in the future, only in the past, no more/fewer than X days away from today, etc. My tool receives a date to execute a database query in the form of "select * from table where created_date >= argument_date." I can perform the validation further into the script, but performing as much validation up front when the arguments are parsed allows you to fail more quickly in the case of invalid input.

I can understand that ArgumentTypeError is available to be used when there is a problem with the arguments' type. But disallowing the use of custom messages in TypeError and ValueError seems like an arbitrary restriction with no pros and at least some cons. I assume that this was not an arbitrary decision and there really was a reason for it, but I can't see what that reason is.
History
Date User Action Args
2017-05-06 03:03:00pgacv2setrecipients: + pgacv2, paul.j3
2017-05-06 03:03:00pgacv2setmessageid: <1494039780.32.0.788090626274.issue30220@psf.upfronthosting.co.za>
2017-05-06 03:03:00pgacv2linkissue30220 messages
2017-05-06 03:02:59pgacv2create