On 08/24/2015 02:45 PM, Alexander Belopolsky wrote:
On Mon, Aug 24, 2015 at 5:32 PM, Ethan Furman wrote:
It is my contention that library code (such as datetime) should raise exceptions
when something exceptional happens, and the program code can then handle it
appropriately for that program:
...
# server program
try:
get_a_datetime_from_somewhere(ltdf=None)
except AmbiguousTimeError, NonExistentTimeError:
log(weird_time_error)
use_default()
I've been criticized on this list for using python-resembling pseudo-code, so I
will
assume that what you show is an actual Python code. In this case,
`get_a_datetime_from_somewhere` and `use_default` lines have no visible effect
on the
program and I have no guess for what they are supposed to do internally.
You're right, I was sloppy. How's this:
try:
some_date = get_a_datetime_from_somewhere(ltdf=None)
except AmbiguousTimeError, NonExistentTimeError as e:
log(weird_time_error, e)
some_date = use_default(e.datetime)
and the datetime attribute of e would be the attempted datetime with the flag
set to None (so it is either still ambiguous, or still doesn't exist), and then
use_default() would do something with it.
I do show in the PEP how a function that raises an error on ambiguous/missing
time can be written.
Writing functions to work around short-comings is not how I like to spend my
time (see my contention above about library code).
If we do go the route of not raising exceptions we should just add your
function to the datetime module and save people from mis-copying it.
--
~Ethan~
_______________________________________________
Datetime-SIG mailing list
[email protected]
https://mail.python.org/mailman/listinfo/datetime-sig
The PSF Code of Conduct applies to this mailing list:
https://www.python.org/psf/codeofconduct/